|
|
Hi,
I want to apply theme for an application. I want to read all controls inside the form
I'm using this code to get controls.
public void ApplyTheme(object ob)
{
System.Windows.Forms.Form f = (System.Windows.Forms.Form)ob;
foreach (System.Windows.Forms.Control ctr in f.Controls)
{
}
}
By using the above code, I can read only parent controls inside the form, can't read the child controls,
Can anybody give me a solution to read all controls including child inside a child also.
Thanks in advance.
Sababathi B
Software Developer as well as Team Coordinator, Working for eXinfoTech
|
|
|
|
|
The solution, is recursion. Have your method call itself so long as ctr has child controls.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Use recursion to get that...
In
foreach (System.Windows.Forms.Control ctr in f.Controls)
{
//Check if ctr again as some child controls and call the method again.
}
Hmmm....but recursion??? I had a problem of StackOverflow exception bcoz of it(in some other application)..
.....
|
|
|
|
|
Spunky Coder wrote: I had a problem of StackOverflow exception bcoz of it(in some other application)..
Well, you need to know what you're doing so you don't cause infinite recursion
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: you don't cause infinite recursion
Well I handled that thing...Actually the application works like the 'Reflector'..So the application loops through the classes(and their properties,innerclasses) and initializes objects at run time ..While looping through StackOverflow exception occurs in the case of a dll having many classes and innerclasses. But i found only recursion as the suitable thing and hence could not avoid it
.....
|
|
|
|
|
Hi Graus,
The following code is working perfectly
private void ReadAllControls(Control Parent)
{
if (Parent.HasChildren)
{
foreach (Control Child in Parent.Controls)
{
GetTheme(Child);
ReadAllControls(Child);
}
}
else
GetTheme(Parent);
}
Try it
Software Developer as well as Team Coordinator, Working for eXinfoTech
|
|
|
|
|
Recursive.
By the way, not all controls are in .Controls, ie Menu
|
|
|
|
|
What is meant by hardcoding values into a program? An explanation with brief example will be highly appreciated.
|
|
|
|
|
First of all I would like to advice you to use a thing they call: Google ... it kinda helps alot.
Secondly, To hard code or hard coding (also, hard-code/hard-coding, hardcode/hardcoding) refers to the software development practice of embedding input or configuration data directly into the source code of a program or other executable object, or fixed formatting of the data, instead of obtaining that data from external sources or generating data or formatting in the program itself with the given input.
Hope it makes sense ...
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
Thank you so much. It makes a lot of sense, more than what I found on google.
cheers.
|
|
|
|
|
Wikipedia[^] is also your friend (as well as google).
Dave
|
|
|
|
|
I am doing a GUI design right now. I have all the templates with me which have space allocated for controls. I have added form's background as this image and placed controls in the correct slots. Since background is an image, it's getting slight delay in loading the form. I am looking for an alternative efficient way to load the background image. Any thoughts ?
|
|
|
|
|
Hi,
Only thing I can think of right now is double buffering, or maybe use an image instead of the background image of the form ...
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
Programm3r wrote: maybe use an image instead of the background image of the form ...
Do you mean image in a picture box ? Picture box is poor in performance.
Programm3r wrote: double buffering
Thanks. I will take a look at this.
|
|
|
|
|
|
Hi all,
I am trying to select the cell of a datagrid as a right click occurs on it .... and I am kinda lost. Can anyone please give me some advice ?
Many thanks in advance
Regardsm
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
Handle the CellMouseClick event in which check if the mouse click is of right button and then select the particular cell
.....
|
|
|
|
|
Thanks for the reply ...
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
|
.... and I'm no longer lost
private void dbGrid_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (e.ColumnIndex != -1 && e.RowIndex != -1)
{
dbGrid.ClearSelection();
dbGrid.CurrentCell = dbGrid.Rows[e.RowIndex].Cells[e.ColumnIndex];
}
}
}
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
Hi again,
So after figuring out how to make the right click work, I'm having trouble with the position of the contextmenustrip. The problem is that the menu pops-up at the incorrect locaion. I'm doing the following:
...CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
...
contextMenuStrip1.Show(dbGrid, e.Location);
...
}
But the contextmenustrip pops-up at the top right hand corner of the DataGridView ?? Am I doing something wrong, if so what ?
Many thanks in advance
regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
Instead of Show use PointToScreen method...Also i think you have to attach the contextmenustrip to the particular cell like dbgrid.rows[index].Cells[index].ContextMenuStrip = contextmenustrip..
check the syntax
"Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)
|
|
|
|
|
|
Just out of curiosity, why would the contextmenu pop-up every second time, that the right-click occurs ??
Another observation, is when I right click on the cell(1) and right-click on another cell(2) and then move back to the previous cell(1) the contextmenu pops-up first time ???
Thanks again.
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|