|
Never mind. Figured it out.
/K
|
|
|
|
|
I have a simple application that need to return value on exit to the his caller process.
the calling process use Process p = Process.Start(startInfo); to call the second one.
In regular .Net I can us the System.Environment.ExitCode to do it, but in the compact framework its doesn't supported.
|
|
|
|
|
Have you tried changing the Main method to return an int ?
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
i have a windows form application, and i want that when i execute the program, program must show me the main form quickly, but my program firstly do some operations (connecting to sql, filling the combobox etc. )
because in form_load function i call a function to fill the combo with sql database's datas.
But user does not want to wait, user wants to see the form very quickly.
In other words, user wants my program to connect sql and to fill the combo AFTER form has been shown to the user.
|
|
|
|
|
The easiest way to make this possible is to put this operations in the Shown Event of the showing form.
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.Shown += new System.EventHandler(this.Form1_Shown);
}
private void Form1_Shown(object sender, EventArgs e) {
MessageBox.Show("Hello world after showing the Form");
}
}
Hope it could help you...
|
|
|
|
|
it does not work
is there anyone having idea_?
|
|
|
|
|
|
|
Why show the user the form if it's not ready to use?
|
|
|
|
|
So he doesn't double click it again, and again, and again... My wife does that - if whatever she runs doesn't show up pretty much immediately, she just clicks and clicks until something happens. Or she gets angry and breaks the keyboard.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
So she'll keep clicking on the ListBox or whatever until it loads instead?
|
|
|
|
|
She wouldn't recognise a listbox if it got up and bit her on the arse.
She works on the principle that "it works with telephones, so it should work here".
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
A common way of showing that the program is running before it's actually usable is to use a splash screen to indicate that something is happening.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
|
Couple of things:
1) When you provide a link to something, it is considered polite to make it clickable. Highlight it, and use the "link" or "link[^]" widgets above the edit text box to do this. The second one of the two is the post common - it provides a "new window" option as well as a standard link.
2) What are you trying to achieve? You have drawn a house, and provided two text boxes, and a button. What do you want to occur when you fill in the boxes and press the button? "the house will go to that certain point" does not really explain what you want.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
|
So? It's not exactly difficult.
At present you are drawing a house - lets just draw a box:
Draw line (x1, y1) to (x2, y1)
Draw line (x2, y1) to (x2, y2)
Draw line (x2, y2) to (x1, y2)
Draw line (x1, y2) to (x1, y1) What happens if you add the numbers you read from the text boxes to each xN and yN coordinate appropriately? Would the box stay in the same place? Or would it move?
That is the basics; now it's up to you to see what happens.
Two little hints:
1) You house is to big to move much - draw it about half the size before you start playing with your code.
2) The drawing coordinates start at the top left of the window, rather than the bottom left as you probably expected - but you have probably realised that while drawing the house in the first place.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
|
Not too bad - it works! There are a couple of things you should look at:
1) If you must use CreateGraphics (and you should avoid it if you can), then you must Dispose it. Graphics handles are scarce resources, and should not be created willy-nilly. The easiest way is:
Pen gPen;
SolidBrush nBrush;
using (Graphics fx = CreateGraphics())
{
gPen = new Pen(Color.Green);
nBrush = new SolidBrush(Color.Blue);
float x = 0, y = 0;
x = float.Parse(textBox1.Text);
y = float.Parse(textBox2.Text);
fx.Clear(Color.Black);
fx.DrawLine(gPen, 200 + x, y, 0 + x, 100 + y);
fx.DrawLine(gPen, 200 + x, y, 400 + x, 100 + y);
fx.DrawRectangle(gPen, x, 100 + y, 400, 200);
fx.DrawRectangle(gPen, 25 + x, 175 + y, 150, 125);
fx.DrawEllipse(gPen, 150 + x, 225 + y, 10, 10);
fx.DrawRectangle(gPen, 250 + x, 150 + y, 100, 100);
fx.DrawLine(gPen, 250 + x, 200 + y, 300 + x, 200 + y);
fx.DrawLine(gPen, 300 + x, 150 + y, 300 + x, 250 + y);
}
2) You don't need to use floats - all the screen coordinates are int , so use those instead.
3) Please don't use Parse on textboxes (or other user input) - it will throw an exception when it fails to convert. For example, when the user empties the textbox, or types an alphabetic character. Use TryParse instead:
using (Graphics fx = CreateGraphics())
{
gPen = new Pen(Color.Green);
nBrush = new SolidBrush(Color.Blue);
int x = 0, y = 0;
if (int.TryParse(textBox1.Text, out x) && int.TryParse(textBox2.Text, out y))
{
fx.Clear(Color.Black);
...
}
}
TryParse never throws an exception, it returns true or false to say the conversion worked.
4) Avoid drawing everywhere (and don't create Graphics objects): draw in the Paint event. In the form designer, add a panel to your form and make it fit the available space (you can also change the Anchor properties to make it resize with the form). Double click the panel, and it will create a Paint event, and show you the code. Make it look like this:
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics fx = e.Graphics;
Pen gPen = new Pen(Color.Green);
int x = 0, y = 0;
int.TryParse(textBox1.Text, out x);
int.TryParse(textBox2.Text, out y);
fx.Clear(Color.Black);
fx.DrawLine(gPen, 200 + x, y, 0 + x, 100 + y);
fx.DrawLine(gPen, 200 + x, y, 400 + x, 100 + y);
fx.DrawRectangle(gPen, x, 100 + y, 400, 200);
fx.DrawRectangle(gPen, 25 + x, 175 + y, 150, 125);
fx.DrawEllipse(gPen, 150 + x, 225 + y, 10, 10);
fx.DrawRectangle(gPen, 250 + x, 150 + y, 100, 100);
fx.DrawLine(gPen, 250 + x, 200 + y, 300 + x, 200 + y);
fx.DrawLine(gPen, 300 + x, 150 + y, 300 + x, 250 + y);
}
Because you don't create the Graphics object, you are not responsible for disposal.
Now all you need to do is create TextChanged handlers for each of the TextBoxes (by double clicking in the designer) and add one line to each:
panel1.Invalidate();
Now whenever the system needs to, your house will be drawn in the new position.
[edit]I really should check code before I post it: TryParse uses out parameters...
Sorry![/edit]
[edit#2]It works much nicer if you invalidate the panel rather than the whole form: I should run code before posting it too...[/edit#2]
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
modified on Sunday, July 11, 2010 3:34 AM
|
|
|
|
|
Alright thanks for the feedback!
|
|
|
|
|
You're welcome!
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Don't remove your messages when you have an answer - it means that the chain of messages looks silly with nothing to refer to.
Leave your questions there, someone else may learn from your experiences.
You can edit your original question though, and change the heading to add "[Solved]" instead.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
don't remove messages that have replies attached. It is against the forum guidelines and results in sloppy threads.
|
|
|
|
|
I've no idea where you're going with this, but it's clearly a part of something bigger. That screen's way too small to move the house around much.
If you want to redraw the house at different locations you'll need to define a point on your house to be an anchor, with coordinates on the screen that correspond to the X and Y values entered by the user. All other drawing coordinates will have to be modified to make them relative to the anchor point.
You can do this by adding X to every x-value and Y to every y-value in all of your drawing methods, but this may need some tweaking. The default 0,0 coordinates for all methods is the upper left corner of the container; if you have an element within an element, it may take further work to get it just right. I'm fairly new to graphics programming, so I'm just beginning to pick up on some of the gotchas - you'll probably find more. Good luck!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
I suggest you look at this[^] little article; it explains the basics of drawing and animation.
|
|
|
|
|