我在WinForm上有几个TextBox.当按下Enter键时,我希望焦点移动到下一个控件?每当文本框获得控制权时,它也会选择文本,以便任何编辑都将替换当前文本.
做这个的最好方式是什么?
如何将TextBox绑定到整数?例如,将单位绑定到textBox1.
public partial class Form1 : Form
{
int unit;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.DataBindings.Add("Text", unit, "???");
}
Run Code Online (Sandbox Code Playgroud) 我在OnInitDialog()上尝试了以下代码,但没有显示任何内容.
m_staticLogo.SetBitmap(::LoadBitmap(NULL, MAKEINTRESOURCE(IDB_LOGO)));
Run Code Online (Sandbox Code Playgroud)
其中m_staticLogo是静态图片控件,IDB_LOGO是png文件的资源ID.
如何将带空格的路径传递给CreateProcess()函数?
以下作品
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if( !CreateProcess(_T("c:\\installer\\ew3d.exe"), // No module name (use command line)
_T("c:\\installer\\ew3d.exe /qr"),//argv[1], // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure …Run Code Online (Sandbox Code Playgroud) 请考虑以下代码:
double v1 = double.MaxValue;
double r = Math.Sqrt(v1 * v1);
Run Code Online (Sandbox Code Playgroud)
r = double.MaxValue在32位机器上r = 64位机器上的无穷大
我们在32位机器上开发,因此在客户通知之前不会发现问题.为什么会发生这种不一致?如何防止这种情况发生?
我计划使用以下内容向TextBox添加功能:
public class TextBoxExt : TextBox
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我们如何使用这个TextBoxExt?反正有没有把这个类放到ToolBox上,以便我们可以将它拖放到表单上?如果没有,使用TextBoxExt的最佳方法是什么?
有这个代码:
using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create)))
{
//save something here
}
Run Code Online (Sandbox Code Playgroud)
我们需要关闭BinaryWriter吗?如果没有,为什么?
public class Options
{
public FolderOption FolderOption { set; get; }
public Options()
{
FolderOption = new FolderOption();
}
public void Save()
{
XmlSerializer serializer = new XmlSerializer(typeof(Options));
TextWriter textWriter = new StreamWriter(@"C:\Options.xml");
serializer.Serialize(textWriter, this);
textWriter.Close();
}
public void Read()
{
XmlSerializer deserializer = new XmlSerializer(typeof(Options));
TextReader textReader = new StreamReader(@"C:\Options.xml");
//this = (Options)deserializer.Deserialize(textReader);
textReader.Close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我设法保存没有问题,FolderOption的所有成员都被反序列化.但问题是如何阅读它?行 - // this =(Options)deserializer.Deserialize(textReader); 不行.
编辑:这个问题的任何解决方案?我们可以达到同样的目的而不分配给它吗?这是将Options对象反序列化为Option.我懒得去做物业.在最高级别上执行将节省大量精力.
有没有办法有一个默认的MessageBox.Show()标题?假设我想将我的应用程序名称作为Message Box标题,我不想一直输入MessageBox.Show(msg,ApplicationName).我只想调用MessageBox.Show(msg).
我有一个C#字符串"RIP-1234-STOP\0\0\0\b\0\0\0 ??? | B?Mp?\ 0\0\0"从调用本机驱动程序返回.
如何从第一个空终止符'\ 0 \开始修剪所有字符.在这种情况下,我只想拥有"RIP-1234-STOP".
谢谢.
c# ×8
winforms ×3
c++ ×1
data-binding ×1
idisposable ×1
mfc ×1
png ×1
text-parsing ×1
using ×1
winapi ×1