|
Have you checked the 'ActiveMdiChild' property of the MDI Parent Form?
MSDN:Activemdichild[^]
Jibesh V P
|
|
|
|
|
Thanks!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
never mind. it happens to every one..
may be coz its friday eve
Jibesh V P
|
|
|
|
|
Although you've managed to get the top window, I thought this was an interesting one so I've had a play around.
Windows has a function EnumChildWindows[^] which gets the windows in Z order.
Something like this in the parent will get you an IEnumerable<Form> of the children in z order.
private delegate bool EnumChildProc(IntPtr hwnd, IntPtr lParam);
[DllImport("User32.dll")]
private static extern bool EnumChildWindows(IntPtr hWndParent, EnumChildProc lpEnumFunc, IntPtr lParam);
private IEnumerable<Form> GetChildrenSortedByZOrder()
{
List<IntPtr> handles = new List<IntPtr>();
if (IsHandleCreated)
{
EnumChildWindows(Handle,
(hWnd, lparam) =>
{
handles.Add(hWnd);
return true;
}, IntPtr.Zero);
}
List<Form> children = new List<Form>(handles.Count);
foreach (IntPtr handle in handles)
{
Form form = FromHandle(handle) as Form;
if (form != null)
children.Add(form);
}
return children;
}
|
|
|
|
|
After a bit of rooting around in the undergrowth of the outer form, I've found the ordered list of MDI windows.
The Form.MdiChildren property is a list of MDI children but the order is fixed in order in which the forms were created.
Enumeration of the Form.Controls collection will reveal an unnamed Control of type System.Windows.Forms.MdiClient whose Controls collection is the dynamically ordered list of MDI child forms. The first item is the form at the top of the Z-order.
private void ShowMdiChildren() {
log.WriteLine("MdiClient control collection");
log.WriteLine("============================");
foreach (Control c in this.Controls) {
if (c is System.Windows.Forms.MdiClient) {
System.Windows.Forms.Control.ControlCollection mdiColl = c.Controls;
foreach (Control mdiChild in mdiColl) {
log.WriteLine("{0,-2} {1, -20} {2, -16} {3}", mdiColl.GetChildIndex(mdiChild), mdiChild.Text, mdiChild.Name, mdiChild.GetType());
}
}
}
log.WriteLine();
}
By manipulation of the collection you can do fun things like reorder the child forms
private void RotateZOrder() {
foreach (Control c in this.Controls) {
if (c is MdiClient) {
Control.ControlCollection mdiColl = c.Controls;
if (mdiColl.Count >= 2) {
mdiColl.SetChildIndex(mdiColl[0], mdiColl.Count - 1);
}
}
}
}
Alan.
|
|
|
|
|
Hi,
I am creating a comma separated file with data from database.
The data is pretty much customer information.
Is there a way to code for special characters, like commas with the customer data?
Thanks!
|
|
|
|
|
I'd recommend to encode it in Base64. That way you can even throw (binary) pictures in there.
|
|
|
|
|
Surprisingly there is a standard for CSV.
Text Fields are surrounding by "". " escapes ", pretty simple.
|
|
|
|
|
How to optimise code every time needs to bind the grid
|
|
|
|
|
Your best of showing what code you think need optimization and others will let you know of potential improvements.
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
sujeet321 wrote: How to optimise code
You do this by appying your VAST knowledge and experience in programming.
|
|
|
|
|
Look at the query first. Make sure you only pick up what you need to display.
Your gridview will be faster automatically.
|
|
|
|
|
In a gridview, how to change the background color of a selected row, on click of a cell in datagridview. Thanks in advance
modified 1-Feb-13 4:11am.
|
|
|
|
|
Handle the CellClick event:
private void myDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
DataGridView dgv = sender as DataGridView;
if (dgv != null)
{
dgv.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
}
}
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Thanks for your reply.
The code which you sent changing the back color of a row, wherever I click in the gridview.
So entire grid resulted in red background color
My issue is to change the selected background color. To describe more, If I click on first row, background color should change to Dark Gray color. after that, if I click on second row, first row should get reverted to previous color and second row background color should be in darkgray color.
|
|
|
|
|
Do you expect me to do everything for you?
Keep a "I changed this" row index, and change it back. Then set the new row, and save the index. It's not exactly rocket science...
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Strange how we both chose Red.
|
|
|
|
|
Easy to type!
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
Set your row default selection colour in your form design, or add the following during initialisation:
gridView.Rows[e.RowIndex].DefaultCellStyle.SelectionBackColor = Color.Red;
And add something similar to the following to your cell click event:
gridView.Rows[e.RowIndex].Selected = true;
|
|
|
|
|
In CellClick event, below statement worked. Thank you.
dgvTestCaseDetails.Rows[e.RowIndex].Selected = true;
|
|
|
|
|
Hi friends,
I am trying to write a log file by using log4net, which should write all log events in default event log. Please help me to do it.
Thanks and Regards
Venkat
|
|
|
|
|
|
|
The same as usually. The Dispose method is called on the objects named in the Using statement.
ThreadAbort raises an exception in the specified thread. It's not an immediate termination of the thread.
|
|
|
|
|
Dave Kreskowiak wrote: The same as usually.
I don't like "Usually" ...
I read from somewhere that [^]lock(x) statement is syntactic sugar, that JIT compiler will autogenerate the following:
<br />
Monitor.Enter(o);<br />
S0;<br />
try {<br />
S1;<br />
} finally {<br />
Monitor.Exit(o);<br />
}<br />
However, for some compiler architecture, your code will not cleanup properly if Thread.Abort called at point "S0" above before the generated try block, thus Monitor.Exit will not be exited.
But hold - I just found out the answer - I missed the update from the referenced post which says M$ corrected the problem:
<br />
Update 4/17/08: This was indeed fixed for the X64 JIT in Visual Studio 2008. Note that when compiling C# code targeting both X86 and X64, if you do not use the /o+ switch, this problem can still occur due to extra explicit NOPs inserted before the try.<br />
<br />
The framework implements a method Monitor.ReliableEnter, by the way, that could be used to avoid orphaning locks in the face of thread aborts, but it's internal to mscorlib.dll. It sets an out parameter within a region of code that cannot be interrupted by a thread abort, which the caller can then check inside the finally block. The acquisition then gets moved inside so that, if the CALL is reached, the finally block is guaranteed to always run. You'd then write this instead:<br />
<br />
bool taken;<br />
try {<br />
Monitor.ReliableEnter(o, out taken);<br />
S1;<br />
} finally {<br />
if (taken)<br />
Monitor.Exit(o);<br />
}<br />
Problem solved!
dev
modified 1-Feb-13 0:09am.
|
|
|
|