Tag: c# 2.0

Combobox onkeypress事件的自动完成function会占用Enter键

我有一个ComboBox与AutoCompleteMode = suggest并处理KeyPress事件,如下所示: private void searchBox_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Return) { // do stuff } } 但是,它没有捕获Enter键。 它可以捕获其他所有内容,因为自动完成下拉列表工作正常。 我也尝试了这里提供的建议: http : //social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/2db0b540-756a-4a4f-9371-adbb92409806 ,将表单的KeyPreview属性设置为true并放置一个表单的KeyPress事件处理程序中的断点: private void Form_KeyPress(object sender, KeyPressEventArgs e) { e.Handled = false; } 但是,即使表单的处理程序没有捕获回车键! 有什么建议? (如果我禁用自动完成function,它会捕获Enter键)

如何使TreeNode不可见? (C#)

可能有一个非常简单的答案,但我很难找到它。 很简单,我有一个TreeNode,我想让它的可见性为false。 (或其他方式不允许在需要之前显示)。 编辑 – 另一个问题? 我很困惑如何没有Visible属性但是有属性: Node.PrevVisibleNode; 这和Node.PrevNode什么Node.PrevNode ? 谢谢,

给定边界框和一条线(两个点),确定该线是否与框相交

给定一个边界框,定义如bounds.min.(x/y/z) , bounds.max.(x/y/z) ,以及3D空间中的两个点(表示为Vector3对象),如何确定是否由两点组成的线与边界框相交?

试图将boxed int转换为byte

代码说明: int i = 5; object obj = i; byte b = (byte)obj; // X 运行时,会在“X”行生成System.InvalidCastException(“指定的强制转换无效”)。 做双重演奏: byte b = (byte)(int)obj; 我本以为你应该能够将一个盒装的int(如果它的值在0..255范围内)转换成一个字节。 任何人都可以对此有所了解吗? (这在.net 2.0中,如果重要的话)。

如何在C#中从LDAP读取TermainsServices IADsTSUserEx属性?

我从AD中读过以下属性, TerminalServicesProfilePath TerminalServicesHomeDirectory TerminalServicesHomeDrive 我已经尝试过DirectoryEntry和DirectorySearcher。 但他们不包括这些属性。 我在vbscript和VC中找到了一些例子来读取它们。 但是我没能在C#中工作。 我错过了一些棘手的事情吗? 编辑:我必须在“Windows Server”上运行它才能使其正常工作吗? 可以从win XP中读取吗?

以流格式保存图片框中的图像

我想保存一个装在图片框中的图片流。当我保存为png格式时它工作正常但是当我想要以其他格式保存它我得到 GDI +exception中发生了一般错误 我的代码: Image Img = pictureBox1.Image; byte[] inputImage = new byte[Img.Width * Img.Height]; System.IO.MemoryStream ms = new System.IO.MemoryStream(); ms.Read(inputImage, 0, Img.Width * Img.Height); if (System.Drawing.Imaging.ImageFormat.Jpeg.Equals(Img.RawFormat)) { pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); } else if (System.Drawing.Imaging.ImageFormat.Gif.Equals(Img.RawFormat)) { ms.Seek(0, SeekOrigin.Begin); pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); } else if (System.Drawing.Imaging.ImageFormat.Png.Equals(Img.RawFormat)) { pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); } else if (System.Drawing.Imaging.ImageFormat.Bmp.Equals(Img.RawFormat)) { pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); }

无法为委托分配具有较少特定参数类型的匿名方法

public class Program { delegate void Srini(string param); static void Main(string[] args) { Srini sr = new Srini(PrintHello1); sr += new Srini(PrintHello2); //case 2: sr += new Srini(delegate(string o) { Console.WriteLine(o); }); sr += new Srini(delegate(object o) { Console.WriteLine(o.ToString()); }); //case 4: sr += new Srini(delegate { Console.WriteLine(“This line is accepted,though the method signature is […]

一列的DataGridview单元格不能有不同的类型

好吧,我有一个datagridview,我有一个列,我想要做的就是控制这个列中的单元格,有时使它成为combobox,有时候是textBox ….等等 我可以让列的单元格只有一种类型,我可以在一列中输入多个单元格吗? 希望很清楚。

C#4.0是否向后兼容C#2.0?

我可以知道C#4.0和C#2.0之间的区别是什么? C#4.0是否向后兼容C#2.0? 我可以说C#4.0是C#2.0的超集(就像C ++对C一样)吗? 谢谢。

如何获取在回调中传递给异步方法的参数

我需要一个传递给CallbackMethodSendRegistration中的AsyncSendRegistrationMethod的Label。 private delegate ResponceFromServer AsyncSendRegistrationDelegate(RegistrationToUser registrationToUser, Label label); private ResponceFromServer AsyncSendRegistrationMethod(RegistrationToUser registrationToUser, Label label) { SetText(label, registrationToUser.Name + ” registration…”); return Requests.DataBase.Authorization.Registration( registrationToUser.Name, registrationToUser.IdRoleUser, registrationToUser.IdGroup); } private void CallbackMethodSendRegistration(IAsyncResult ar) { var sendRegistrationDelegate = (AsyncSendRegistrationDelegate)ar.AsyncState; var responceFromServer = (ResponceFromServer)sendRegistrationDelegate.EndInvoke(ar); if(responceFromServer.IsError) { //here need label.Text } else { } }