|
cuz my boss want all windows for our app (and there are hundreds!) to be in one singe container (mdi parent)...
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Straight off I don't think there's any easy way to achieve that, if I understand what your boss want. How about a MessageBox? Is MessageBox has to be child too? How about Open File dialog, folder browser dialog? The dialog form is no different from an Open File dialog box, IMO.
If your boss really must have that, you may consider hiding Form1 and show Form2, then when user select an action (OK or Cancel or Close), then hide Form2 and Show Form1. But the handling of DialogResult and returned value can be a mess.
So back to my original question, why the dialog form needs to be MDI child?
|
|
|
|
|
lol!
i see your point... what i dont get is why cant a dialog be an mdi child? silly microsoft
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
The best I can think of is to not have it as a mdiChild but a normal form - use showDialog but pass the MDI Container's child rectangle property to the forms constructor. You can then use the LocationChanged event to disallow movement of the dialog outside of that rectangle.
Passing the ClientRectangle doesn't work, it needs to be
RectangleToClient(ClientRectangle)
or
MdiParent.RectangleToClient(MdiParent.ClientRectangle)
if called from a child.
The X and Y (Top and Left) properties will give negative values so you'll need to subtract them from 0 to get the positive values you need.
This code works in the location changed (I'm sure it could be tidied up/improved but it does the job) where LimitRect is the rectangle passed above.
if (Top < (0 - LimitRect.Top))
{
Top = 0 - LimitRect.Top;
}
if (Left < (0 - LimitRect.Left))
{
Left = 0 - LimitRect.Left;
}
if (Right > LimitRect.Right)
{
Left = (LimitRect.Width - LimitRect.Left) - Width;
}
if (Bottom > LimitRect.Bottom)
{
Top = (LimitRect.Height - LimitRect.Top) - Height;
}
Dave
|
|
|
|
|
thanx man, ill look into it over the weekend !
it just hit 5pm here in south africa so im going home!
thanx again, have a go0d one!
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
I would create a custom event on the form, and fire it from the forms destructor. Pass the DialogResult is the EventArgs and handle the event from the calling form.
|
|
|
|
|
This was an interesting problem. I managed to solve it properly and made a little article here[^] out of it. Hope it helps.
Dave
|
|
|
|
|
Hey dave
Thanx again for that article, ive alredy implemented it in my app!!
i came across a strange bug tho, or maybe im just missing something
there is a difference between your demo and my app. i have FrmMain which is my mdiContainer, on that i have a menuStripItem "users", it shows FrmUsers (this is basicly a list of all the users registered for that application - this is not the dialog). On FrmUsers i have btnAddUser which shows FrmAdduser(this is the dialog window where i implemented your code).
so with your initial code the dialog window was confined within the rectangle of FrmUser which isnt even an mdiContainer, but the problem was FrmAddUser often is bigger than FrmUser (this depends on how many users are registered cuz FrmUser Resizes itself depending on how many rows in the DataGridView).
in an atempt to rectify this i did the following in FrmUsers...
foreach (Control thisControl in this.MdiParent.Controls)
{
if (thisControl is MdiClient)
{
}
}
this is where i found the bug, the rectangle that FrmAddUser is restricted to is in the wrong place! The X axis point is correct but the Y axis point is too low. in other words the rectangle is about 100 pixels(rough guess) below FrmMain
any idea sa to why this happens?
i could e-mail you a demo of this problem if it will help
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Yeah, email it to me at
// deleted;
(typed it like that toavoid spam bots!) and I'll have a look.
Dave
modified on Wednesday, February 20, 2008 7:42 AM
|
|
|
|
|
Further thinking about your requirement, I just remember something that I did in a project.
You can have a "container" form, let's say FormContain form to contain both the FormList and FormUpdate. FormContain has a panel, and you will put both listing form and update form in the panel. Base on user action, you can bring FormList or FormUpdate to front.
|
|
|
|
|
thanx man, ill look into it over the weekend!
it just hit 5pm here in south africa so im going home!
thanx again, have a go0d one!
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
I want to dial a number from COM port.I am using Nokia 6300 as a modem which is connected to USB port. Even though computer is accepting mobile as a modem i am getting error in port opening. Sample programs which i used to run application gives error "No phone is connected" or "Unable to open port as it is busy in other application".
So can anybody tell me what may be the problem & how to overcome from it? Can anybody give me correct code to dial a number from COM port in C#.Net?
|
|
|
|
|
It could be due to the baud rate. This[^] article is about sending SMS but it may help. Once connected you should be able to use standard AT commands to dial.
Dave
|
|
|
|
|
As you have said, the nokia modem is connected to USB port. Please make sure that you are using the same port in your application. A common mistake people do is to try to open a COM port #1 or #2 instead of USB one.
Manoj
Never Gives up
|
|
|
|
|
hi there,
i m having problem that i have some float value in string, and i want to convert it in float but the precision must be 4
e.g.
string a = "83.834244245";
float b = Convert.ToSingle(a);
now please tell how can i reduce precision ?
Becoming Programmer...
|
|
|
|
|
First create a subString of the required precision. Then Parse the string for the float value.
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
that will take too much time, i have about 1 lakh strings, please tell any short way
Becoming Programmer...
|
|
|
|
|
This seems a little clumsy but it works
float b = (float)Math.Round(decimal.Parse(a), 4);
The Math.Round method uses 'Bankers Rounding' which may not acheive the result you require. If not you may need to use this which is even clumsier
float b = float.Parse(decimal.Parse(a).ToString("N4"));
Dave
|
|
|
|
|
DaveyM69 wrote: float b = float.Parse(decimal.Parse(a).ToString("N4"));
thanks, it works
Becoming Programmer...
|
|
|
|
|
DaveyM69 wrote: This seems a little clumsy but it works
float b = (float)Math.Round(decimal.Parse(a), 4);
That's not clumsy at all. That's exactly what I would suggest.
DaveyM69 wrote: The Math.Round method uses 'Bankers Rounding' which may not acheive the result you require. If not you may need to use this which is even clumsier
float b = float.Parse(decimal.Parse(a).ToString("N4"));
Now, that is clumsy. Converting a string to a double, to a string, to a float... Why is there no base64 and serializing to xml in there?
If you want a different kind of rounding, just specify that in the call to Round:
float b = (float)Math.Round(decimal.Parse(a), 4, MidpointRounding.AwayFromZero);
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Guffa wrote: Why is there no base64 and serializing to xml in there?
I did say it was even clumsier!
I haven't come across MidpointRounding.AwayFromZero before - more learning to do
Dave
|
|
|
|
|
Hi,
if the values well are within int limits, then you can do things such as:
float b = Convert.ToSingle(a);
int b4= (int)(10000.0*b+0.5);
b=0.0001*b4;
This does not create any objects; variants of it will all have similar performance.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
i think DaveyM69 gave good solution, anyway thank you too
Becoming Programmer...
|
|
|
|
|
The bankers rounding, is that what you want?? (you do realize it produces even numbers only?)
or the clumsy and slow one with an unnecessary ToString() and Parse()??
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
no, i dont want bankers rounding,
yeah i know your way is good, but a little bit long as i have to write it about in 100 lines in a big loop
so you can think 100 * 3 repeating lines will hard to understand and a little mistake can destroy the project
Becoming Programmer...
|
|
|
|