我试图将System.Windows.Forms.Control添加到给定的窗体控件集合.我这样做是通过创建类型控件的私有字段,然后将此字段实例化为构造函数中的System.Windows.Forms.Control的新实例.
在运行时,我试图通过执行类似以下代码示例的操作,将_placeholder变量的类型更改为TextBox.所以基本上我试图拥有一个Control类型的占位符,并在运行时将其更改为另一个控件,如TextBox或Label.我的问题是我的表单上没有显示任何内容?任何见解将不胜感激.
public class MyForm : Form
{
System.Windows.Forms.Control _placeholder = null;
public MyForm()
{
_placeholder = new System.Windows.Forms.Control();
this.Controls.Add(_placeholder);
ChangeToTextBox();
}
public void ChangeToTextBox()
{
_placeholder = new TextBox();
}
}
Run Code Online (Sandbox Code Playgroud) 我试过了
UIManager.getDefaults().put("TitledBorder.font", Font.BOLD);
contentPanel.setBorder(new TitledBorder("Client Downloader"));
Run Code Online (Sandbox Code Playgroud)
但它并没有让它变得大胆.它看起来只是分开.
这是错误的方式吗?
我正在尝试替换文本字符串中的一组单词。现在我有一个循环,它表现不佳:
function clearProfanity(s) {
var profanity = ['ass', 'bottom', 'damn', 'shit'];
for (var i=0; i < profanity.length; i++) {
s = s.replace(profanity[i], "###!");
}
return s;
}
Run Code Online (Sandbox Code Playgroud)
我想要一些工作更快的东西,并且可以用与###!原始单词长度相同的标记替换坏词。
我正在写一个程序,我将数字乘以5 ...例如:
var
i:integer;
k:int64;
begin
k:=1;
for i:=1 to 200000000 do
begin
k:=5*(k+2);
end;
end;
end.
Run Code Online (Sandbox Code Playgroud)
但是当我编译并启动我的程序时,我得到一个溢出整数错误.我怎么解决这个问题?
class Sample
{
public:
Sample();
Sample(int i);
Sample(Sample& s);
~Sample();
};
Sample::Sample()
{
cout<<"Default constructor called\n";
}
Sample::Sample(int i)
{
cout<<"1-argument constructor called\n";
}
Sample::Sample(Sample& s)
{
cout<<"Copy constructor called\n";
}
Sample::~Sample()
{
cout<<"Destructor called\n";
}
void Fun(Sample s)
{
}
int main()
{
Sample s1;
Fun(5);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我期望隐式转换为5.但是,当我编译上面的代码时,我得到以下错误:
main.cpp:7:8: error: no matching function for call to ‘Sample::Sample(Sample)’
main.cpp:7:8: note: candidates are:
Sample.h:10:3: note: Sample::Sample(Sample&)
Sample.h:10:3: note: no known conversion for argument 1 from ‘Sample’ to ‘Sample&’
Sample.h:9:3: …Run Code Online (Sandbox Code Playgroud) List<string> dinosaurs = new List<string>();
dinosaurs.Add("Tyrannosaurus");
dinosaurs.Add("Amargasaurus");
dinosaurs.Add("Deinonychus");
dinosaurs.Add("Compsognathus");
Run Code Online (Sandbox Code Playgroud)
我为什么要使用ReadOnlyCollection如下:
var readOnlyDinosaurs = new ReadOnlyCollection<string>(dinosaurs);
Run Code Online (Sandbox Code Playgroud)
代替:
dinosaurs.AsReadOnly();
Run Code Online (Sandbox Code Playgroud)将List设置为ReadOnlyCollection或AsReadOnly的真正优势是什么?
假设我有一个转换后的 HTML 文档,并且我想在父文档周围包裹一个额外的标签,以便我可以读取head和body。我该如何用 C# 做到这一点?该文件用作XDocument.
改变
<html>
<head>
<!-- data -->
</head>
<body>
<!-- data -->
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
到
<open>
<html>
<head>
<!-- data -->
</head>
<body>
<!-- data -->
</body>
</html>
</open>
Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码来获取自定义用户控件,从中制作位图,然后将其保存到隔离存储中以用于WP8 Live Tile.
public static void UpdateTile()
{
var frontTile = new LiveTileRegular(); // Custom Control
frontTile.Measure(new Size(173, 173));
frontTile.Arrange(new Rect(0, 0, 173, 173));
var bmp = new WriteableBitmap(173, 173);
bmp.Render(frontTile, null);
bmp.Invalidate();
const string filename = "/LiveTiles/LiveTileRegular.jpg";
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isf.DirectoryExists("/LiveTiles"))
{
isf.CreateDirectory("/LiveTiles");
}
using (var stream = isf.OpenFile(filename, FileMode.OpenOrCreate))
{
bmp.SaveJpeg(stream, 173, 173, 0, 100);
}
Debug.WriteLine("Image Exists: " + (isf.FileExists(filename) ? "Yes" : "No")); // Displays "Yes"
}
ShellTile.ActiveTiles.First().Update(new FlipTileData
{
Title = …Run Code Online (Sandbox Code Playgroud) c# isolatedstorage dynamic-image-generation live-tile windows-phone-8
什么是using namespace std;近年来C++?
在诸如Turbo C++之类的旧编译器中,这似乎不受支持,因为它会导致编译器错误.在最近的C++编译器中,这是编译和运行程序的唯一方法.