|
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
|
|
|
|
|
i solved it by another way
form1
form2 f2 = new form2();
f2.showdialog();
f2.dispose();
if(f2.IsDispose)
{
textbox1.text = valuetext;
}
// value text is static variable in form2
thank u for ur replay
|
|
|
|
|
DO NOT DO THAT!
See here[^]
When you dispose a control, you have no control over when it's memory is available - the garbage collector is a liberty to remove it at any time. The code may work now, in testing, and then fail intermittently for no apparent reason later.
To add to that: What do you think static variables are? Again, this will cause you problems. Read up on the difference between a STATIC and a PUBLIC variable.
Also, it is considered bad practice to expose fields directly, and it makes it difficult to implement changes later. Use a property instead.
To add to the list: Don't use f2.ShowDialog() alone - always surround it with an "if" as in:
if (f2.ShowDialog() == DialogResult.OK)
{
...
} Otherwise, what happens if the user decides he doesn't want to enter a value?
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
|
|
|
|
|
|
OriginalGriff wrote: When you dispose a control, you have no control over when it's memory is available - the garbage collector is a liberty to remove it at any time. The code may work now, in testing, and then fail intermittently for no apparent reason later.
The garbage collector cannot remove a disposed control if any references to it exist. If there are any user fields or properties, within a control, those fields will continue to be valid, even after the control is disposed, with the exception of properties that explicitly check for isDisposed and will throw exception exception if it is set.
As for the best way to return the content of a form that is invoked modally, I would suggest that rather than using events, one (1) define a class which contains the form's contents and an enumerated type listing methods of exit; (2) define a method in the form which will ShowDialog itself and then return an object of the class in '1' filled with the values from the form; (3) define a static method in the form which will create a new instance, call the method in '2', and dispose of the instance. That would avoid any excess dependencies between the child form and the main form, and avoid having to add any extra code into the calling form.
|
|
|
|
|
Hi,
I have an outlook plug-in and it is working fine, but I have one issue there are few buttons and I am trying to use icons/ images on buttons with text content.
Please let me know how to use icons/images for buttons in Outlook plug-in.
Thanks.
|
|
|
|
|
Hi,
You can use FaceId properties for add image in your button. For example
_objNewToolBarButton.Caption = "My ToolBar Button";
_objNewToolBarButton.FaceId = 65;
For more, visit Outlook 2007 Add-in Using Microsoft Visual C#.NET[^]
Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Hi all,
I've been trying to solve this problem for over an hour and as I'm a rookie I know that what I want to do is easy to implement, but my lack of experience is preventing me from doing so. With that said, I have some code for a ZedGraph dynamically updating control. Notice that the variable double time controls the x Scale. This code is executed in a timer tick event in order to draw the line on the graph. However, as the x-scale is driven by Environment.Tickcount (which is totally independent of the timer) the graph x-axis increments regardless of whether the timer is enabled or not. I want the double time to be replaced with a double that is based upon the elapsed time of the timer and not the Environment.TickCount, but I can't figure this out. Maybe because I'm too tired... Thanks in advance for any help.
if (zedGraphControl1.GraphPane.CurveList.Count <= 0)
return;
LineItem curve = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
if (curve == null)
return;
IPointListEdit list = curve.Points as IPointListEdit;
if (list == null)
return;
double time = (Environment.TickCount - tickStart) / 1000.0;
list.Add(time, dblLabel);
Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;
if (time > xScale.Max - xScale.MajorStep)
{
xScale.Max = time + xScale.MajorStep;
xScale.Min = xScale.Max - 30.0;
}
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();
|
|
|
|
|
Just set up:
private double myTime = 0.0; as a class field.
In your Load event or constructor:
Timer tim = new Timer();
tim.Interval = 1000;
tim.Tick += new new EventHandler(timer_Tick);
tim.Start(); And add the Tick event handler:
void timer_Tick(object sender, EventArgs e)
{
myTime+= 1.0;
}
However, it may be easier and better to save the start time as a DateTime; and subtract it from DateTime.Now in your update method. You can then get the elapsed seconds from the resulting TimeSpan.
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
|
|
|
|
|
|
You're welcome!
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
|
|
|
|