Spyru Posted October 4, 2003 Posted October 4, 2003 I would like to... ... retrieve the active control ... check if it is a textbox ... insert some text in it Thanks grtz, Spyru :p Quote
aewarnick Posted October 4, 2003 Posted October 4, 2003 Here is one snippet: foreach(Control c in this.Controls) { try { if(c is Label || c is GroupBox || c is Panel || c is LinkLabel || c is CheckBox || c is RadioButton) ((Control)c).BackColor= Color.FromArgb(0,0,0,0); Here is a full method: /// <summary> /// Returns the focused control on a form. If you want only the focused control of a panel or tab page ext. /// Just make f null and send a control to the method otherwise make c null and send a whole form. Returns /// null if no control is focused. /// </summary> public static Control GetFocusedControl(Form f, Control c) { if(f != null) { foreach(Control d in f.Controls) { if(d.Focused) { FocusedControl= d; } else { GetFocusedControl(null, d); } } } else if(c != null) { foreach(Control d in c.Controls) { if(d.Focused) { FocusedControl= d; } else { GetFocusedControl(null, d); } } } return FocusedControl; } Quote C#
aewarnick Posted October 4, 2003 Posted October 4, 2003 this.Text.Insert(10, "Insert this at index 10"); Quote C#
Spyru Posted October 4, 2003 Author Posted October 4, 2003 I am sorry, I forgot to say I was working with Visual Basic .NET. :eek: Quote
aewarnick Posted October 4, 2003 Posted October 4, 2003 .net languages are very similar. You can probably translate to make your own code. Quote C#
Spyru Posted October 4, 2003 Author Posted October 4, 2003 Yeah I think I can do that, but how do I retrieve the width of my form. Because when I use pgbLaden.Left = Form1.ActiveForm.Width - 142 I get an error: An unhandled exception of type 'System.NullReferenceException' occurred in VideoBase.exe Additional information: Object reference not set to an instance of an object. grtz Spyru Quote
aewarnick Posted October 4, 2003 Posted October 4, 2003 Me.Width and Me.Height Me.ClientWidth and Me.ClientHeight - without title bar. When you get that type of exception it means that one of your variables is nothing. It has been declared but has no value at all. Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.