|
Hello,
i have a problem with my dialogs. When i create a new dialog i use the methode form2.Show(); But when i close the old dialog what was created before the form2 dialog, the form2 dialogs also closes?
how can this be fixed?
greetings
Sander
|
|
|
|
|
This is happening because you closed the startup form for your application.
For example, the common misconception is that a splash screen can be the startup form for an application. You can't do this. When the startup form closes, it takes the application's message pump with it, closing down the entire application.
The startup form of your app should be the main form your application uses for the builk of it's user interface. Any other forms are created, in a heirarchy, from this form and displayed. You can NOT transfer the application's message pump from form to form.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How can i start the new form as a new application then because that is what i want then.
greetings
Sander
|
|
|
|
|
This[^] might help you out. Just remember to change the startup type in your project properties to Sub Main, instead of whateverForm.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
You need to run the message pump for the other dialog on a separate thread. Something like
void ShowSecondDialog()
{
new Thread(new ThreadStart(RunMessagePump)).Start();
}
void RunMessagePump()
{
Application.Run(new Form2());
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi,
I have just started to learn c# and I need to write a program that gets the factorial of a number using a "for" loop. Could anyone help me as i'm having a hard time trying to write it.
thanks
|
|
|
|
|
Sounds like homework... but I think I have a good day...
public long Factorial(long number) {
long result = 1;
for (int i = 2; i <= number; i++)
result *= i;
return result;
}
|
|
|
|
|
how sad
|
|
|
|
|
I have made a C# .NET 2002 based exe which I want to run at the startup of system which is Windows 98 based. Now I added the exe name in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run so that it could be run whnever the system starts.
This exe is supposed to run a batchfile (which is placed in the same location where the exe is) as the exe starts running. Now I tested it in the debug mode and it works fine (i.e properly runs the batch file in new process ) but whn this exe is executed frm startup the exe starts running but can't run the batch file.
Can anyone tell me what wrong I am doing. Do I have to set the directory name of this exe in the registry or what?
Thanks
Bilal
Bilal Farooq
|
|
|
|
|
Without seeing your code, it's a little difficult to tell you what you're doing wrong. But, I can take an educated guess at it.
The standard problem with this is that you're not using a fully qualified path to find the file you're trying to run. You're probably just specifying something like myBatchFile.bat , assuming that that file will be in the current directory. This is almost always the case and a very bad assumption to make. You show never assume that the current directory is whatever you think it is. Instead, always(!) build a complete path to to the file you want, then use that full path in your command line that you want to execute.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Here's some code:
void DrawLine(Graphics g)
{
Pen p = new Pen(Color.Blue, 2);
p = c_xy.GetNextPen(); //returns an index of an array of Pens in
//a generic class, (i.e. Pen p1[0]..)
//different Color, different Font
g.DrawLine( p, x1, y1, .....)
How can I draw a line with an arrow or triangle on the end so that it
is obviously visible, that is it looks like an arrow on the end of a line
and not a "sharpened pencil".
I've read a bit of the MSDN and messed around with some code but can't seem to sort out this LineCap/Arrow/Triangle stuff. Not very clear to the novice...thanks
|
|
|
|
|
Hi again,
if the predefined LineCap constants are too small for you, then you can define a CustomLineCap (namespace System.Drawing.Drawing2D) by yourself. There is already one implementation in the .Net framework which draws an arrow of selfdefined size.
So when you create your pens instead of assigning the EndCap/StartCap properties do the following:
pen.CustomStartCap = new AdjustableArrowCap(10, 10, true);
pen.CustomEndCap = new AdjustableArrowCap(5, 5, true);
Don't forget: using System.Drawing.Drawing2D;
|
|
|
|
|
|
Hi,
I am making a program and I need to get the path to the main application exe. How to do that the easies way? In Delphi there was a simple way, just reading the property PATH in the class APPLICATION. What is C# way for that?
Millan
|
|
|
|
|
It's quite similar: Application.StartupPath.
---
b { font-weight: normal; }
|
|
|
|
|
Use Environment.CurrentDirectory Property
|
|
|
|
|
Yes, thanx. Stupid me. I used Application.StartupPath. Both works ok.
|
|
|
|
|
That's not correct, I'm afraid.
Environment.CurrentDirectory is just the current directory, but this can change if you use a FileOpenDialog , for example.
He should indeed use Application.StartupPath or Path.GetDirectoryName(Application.ExecutablePath) .
Regards,
mav
|
|
|
|
|
Hi was woundering how to change the quality of background images on my controls .
My backgrounds seem "grainy" like they are of a lower bpp... i was looking around in my program and the only thing remotley like what im after, that i could find, was BackgroundImage.PixelFormat but that is GET only
Sorry if im bring a muppet... this does seem like such a simple thing, that would be on the properties toolbar ... but I just cant find what to do.
Cheers.
|
|
|
|
|
If the image is not being drawn at it's correct size, then the interpolaton mode needs to be bicubic or similar, or you'll lose quality in the resize operation. Not sure how to set this for a control, I'm talking about if I am drawing the image myself.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
please tell me how to put a progress bar in a sttus bar .
as it is in MS Word.
saurabh walia
|
|
|
|
|
You mean in the browser? Can't be done.
You can set the text that is displayed, though:
var done = 42;<br />
window.status = 'Progress: '+done+'%';
---
b { font-weight: normal; }
|
|
|
|
|
You'd have to do an OwnerDraw status bar. Something like this.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
When I update the data in my PropertyGrid, the PropertyGrid scrolls to the last selected property. The user is going to be scrolling through the properties as they update, so I need to disable this auto scrolling feature. I played around with the AutoScroll property but that didn't seem to do the trick. Has anybody else seen this problem. My Google search didn't produce any answers.
Thanks in advance
|
|
|
|
|
Just in case someone else encounters this problem, here is my current solution:
1) Extend the PropertyGrid class.
internal class HookPropertyGrid : PropertyGrid<br />
{<br />
public VScrollBar VScrollBar<br />
{<br />
get<br />
{<br />
object view = Controls[1];<br />
string className = "System.Windows.Forms.VScrollBar";<br />
return (VScrollBar)PluginGuiUtil.GetFirstControlOfType((Control)view, className); <br />
} <br />
}<br />
<br />
public int GetVScrollPos()<br />
{<br />
if (null != VScrollBar)<br />
{<br />
return VScrollBar.Value;<br />
}<br />
return 0;<br />
}<br />
<br />
public void SetVScrollPos(int pos_)<br />
{<br />
if (null != VScrollBar)<br />
{<br />
VScrollBar.Value = pos_;<br />
}<br />
}<br />
}
2) Before you set the selected object of the PropertyGrid, save off the current scroll pos. After setting the selected object, restore the previous scroll position.
int pos = m_propertyGrid.GetVScrollPos();<br />
<br />
PropertyTable props = new PropertyTable();<br />
<br />
CreateKnownProps(props);<br />
<br />
PopulateKnownProps(props, e_);<br />
<br />
CreateAndPopulateUnknownProps(props, e_);<br />
<br />
m_propertyGrid.SelectedObject = props;<br />
<br />
m_propertyGrid.SetVScrollPos(pos);
The only problem I have seen with this solution is that a selection rectangle will be drawn at the wrong location initially. As soon as you move the scroll bar the selection jumps back to the correct item. This problem only occurs if the selected item is off screen.
|
|
|
|