|
already did it... no change
|
|
|
|
|
I suggest doing the following:
1. Extend the ProgressBar class and Set a property for DisplayText.
2. Everytime the displaytext is changed, you can invalidate the progressbar.
3. Draw the progressbar by overriding the onpaint event.
4. From the background worker, only update the progressbar's DisplayText property.
|
|
|
|
|
can you please share with me what you've done ?
I'm new with all the graphic change stuff, therefor your example will help/teach me ...
thanks in advance
|
|
|
|
|
I overlooked the complete answer provided by Luc.
Luc has provided a link to a custom progress bar. That would be the best thing to do for now.
<added>
What I have done is in my software. And it was basically to create various colored custom bars. It was similar to the link that Luc has provided.
|
|
|
|
|
another strange issue,
after the percent counting is finishes, the percent string disappears just after the progressBar.value got to it maximum value.
that's the code
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
...
progressBar1.Value = e.ProgressPercentage;
progressBar1.Refresh();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
updateText();
}
private void updateText()
{
int percent = (int)(((double)(progressBar1.Value - progressBar1.Minimum) /
(double)(progressBar1.Maximum - progressBar1.Minimum)) * 100);
using (Graphics gr = progressBar1.CreateGraphics())
{
gr.DrawString(percent.ToString() + "%",font, Brushes.Black,
new PointF(progressBar1.Width / 2 - (gr.MeasureString(percent.ToString() + "%",
SystemFonts.DefaultFont).Width / 2.0F),
progressBar1.Height / 2 - (gr.MeasureString(percent.ToString() + "%",
SystemFonts.DefaultFont).Height / 2.0F)));
}
Thread.Sleep(100);
}
in this code, the percent string disappears...
but i notcide that if i add another progress bar (progressBar2) and at the end (in backgroundWorker_RunWorkerCompleted ) i add progressBar2.Value = X; , the percent in progressBar1 (the percent remain on his place after the maximal value was reached)
what can it be ? and how can i solve it ?
thanks
|
|
|
|
|
|
Emran Hussain wrote: I did not find any section dedicated to Visual Studio
On the left hand side of the screen, under "General Discussions", second forum below "The Lounge": "Visual Studio"
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Thank you for showing me the section. I have posted my question there and going to delete from here.
|
|
|
|
|
Hi,
I am wondering, I have developed many Windows and Web Form Controls in .NET 2.0. Now, if I want to develop application in .NET 4.0 in Visual Studio 2010, will I be able to use them without any modification ?
|
|
|
|
|
In all probability, you should be able to do so.
However, a few of the methods you may have used in 2.0 may be deprecated.
|
|
|
|
|
Hello. I wrote a simple select area, but its working slow when form is maximized, who knows some alternative fast methods for this
here is my code
sry for bad english
public partial class Form1 : Form
{
bool canResize;
int mX, mY;
Rectangle rect = new Rectangle();
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(new Pen(Brushes.Purple, 2), rect);
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
canResize = true;
mX = e.X; mY = e.Y;
rect.Location = new Point(mX, mY);
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
canResize = false;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (canResize)
{
if (mX < e.X)
{
rect.X = mX;
rect.Width = e.X - mX;
}
else
{
rect.X = e.X;
rect.Width = mX - e.X;
}
if (mY < e.Y)
{
rect.Y = mY;
rect.Height = e.Y - mY;
}
else
{
rect.Y = e.Y;
rect.Height = mY - e.Y;
}
this.Invalidate();
}
}
}
|
|
|
|
|
Hi,
I suggest you don't create new pens all the time; create one and keep it as a class member instead.
|
|
|
|
|
it did not help
anyway thx
modified on Sunday, April 18, 2010 5:41 AM
|
|
|
|
|
Im new to c# and build building a program anyway ive moved the code to login to another class as it needs to be reused.
<pre>MessageBox.Show("Login Function runing");
LoginClass.DoLogin(this);
MessageBox.Show("Login finished");</pre>
however unlike everywhere else in c# the as soon as the class method is run the second messagebox is shown even though the login function code keeps executing.
Is there any way to make the login class execute but for the current class to pass until its finished ?
|
|
|
|
|
without seeing more, hard to tell - it sounds like your login class is doing its work asynchronously/in a seperate thread - and you actually need synchronous behaviour .. .
If I were doing it in C++ and couldnt modify/re-write the login class, I'd be looking at putting a waitevent in there, but without seeing more details of login class, right now Im not sure what I'd be waiting on or even if Login Class can signal when its finished for example ...
'g'
|
|
|
|
|
Run the login code in a thread and have it post a custom event when it's finished. Itn the parent class, you can then wait for that event to fire before allowing the code to proceed.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Its not as simple as it runs almost instantly is it? Try checking if your class actually executes - just run in debug and step through the code.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
How you are everybody ?
we are developing a business process like diagram .
i am responsible for designing the GUI of the activities on the white board
i have decided to make each activity like a user control .
but the problem now , i need the user control to be clipped only to the shape of the image (the image of the activity itself)
i need the whole user control on dropping it over the whiteboard to take only the shape of the image itself .
how can i do that in C# Graphics , do you have any sample code or anything for the above task ?
it will be greatly appreciated .
Thanks everyone
Human knowledge belongs to the world.
|
|
|
|
|
maybe this will help.
I know it shapes a hole winform but the same principle should apply to a custom/user control.
It describe how to shape a form based on a bitmap, graphic path and more.
Also this could help.
|
|
|
|
|
i have two forms
form1 contain textbox1 and buttonsearch //click form2 is opend
form2 contains textbox2
i want when user close form2 the value of textbox1 equals value of textbox2 in form2
|
|
|
|
|
So what is the problem you are facing.Can have some property in form1 which set the value in textbox1 and set this property from form2.
Are you asking somthing else?
|
|
|
|
|
Not really good practice - it means form2 has to know about form1 and cannot be used without it. Better to use an event handler in form1 and a property in form2, as many forms can then use form2.
Better still is to use a custom event in form2 which returns the value via a customized EventArgs.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Obiuosly this is thebetter way and having least coupling.
|
|
|
|
|
textbox1 i can't see it in form to its modifier private
|
|
|
|
|
If you specifically want an operation to happen when a form closes, then add an event handler to the close event of that form.
Form1 - assuming form 1 creates form2 and displayed it with form2.Show():
form2.Closed += new EventHandler(form2_Closed);
...
void form2.Closed(object sender, EventArgs e)
{
textbox1.Text = form2.MyTextProperty;
}
Declare
public string MyTextProperty
{
get { return textboxInForm2.Text; }
set { textboxInForm2.Text = value; }
} In form2.
If you show form2 via ShowDialog(), then just access the property - you don't need the event.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|