|
By the way.
Usually, when I want to drag a winodw, I click and hold the ControlBox and drag the window.
How can make move the window when I click and hold on a place in the window itself?
|
|
|
|
|
Hello,
Here is a code which might helps you.
I used the methods in a basic form and my inherit form called the public method. (Just in case you are wondering why it's public)
private Point _startDragPoint;
private System.Timers.Timer TimerMovePad;
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.yourFormMouseUp);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.yourFormMouseMove);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.yourFormMouseDown);
public void MovePadMouseDown(System.Windows.Forms.MouseEventArgs e)
{
_dragModeEnabled = true;
_startDragPoint = new Point(e.X, e.Y);
}
public void MovePadMouseMove(System.Windows.Forms.MouseEventArgs e)
{
if (_dragModeEnabled == false)
return;
MovePad(e);
}
public void MovePadMouseUp(System.Windows.Forms.MouseEventArgs e)
{
if (_dragModeEnabled == false)
return;
_dragModeEnabled = false;
MovePad(e);
}
private void MovePad(System.Windows.Forms.MouseEventArgs e)
{
if(TimerMovePad == null)
{
this.TimerMovePad = new System.Timers.Timer();
this.TimerMovePad.Interval = 100;
this.TimerMovePad.Elapsed +=new System.Timers.ElapsedEventHandler(TimerMovePad_Elapsed);
}
if (TimerMovePad.Enabled == false)
{
TimerMovePad.Enabled = true;
}
if(_movementok == true)
{
_movementok = false;
int delta_x = e.X - _startDragPoint.X;
int delta_y = e.Y - _startDragPoint.Y;
this.Location = new Point((this.Location.X + delta_x), (this.Location.Y + delta_y));
}
}
private void TimerMovePad_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
TimerMovePad.Enabled = false;
_movementok = true;
}
private void yourFormMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
MovePadMouseDown(e);
}
private void yourFormMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
MovePadMouseMove(e);
}
private void yourFormMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
MovePadMouseUp(e);
}
Hope it helps!
All the best,
Martin
|
|
|
|
|
thanks
|
|
|
|
|
hi..
how to set a button as default..
that when i press the Enter button, the button event should occur
regards,
hiremath
|
|
|
|
|
I don't know how you can set a button as default... But instead of this, you can set the KeyPreview property value "true" and add handle the KeyDown event of the form, and call the same method that you call with the button click event.
|
|
|
|
|
Hello,
I think the AcceptButton property is what you are looking for.
yourform.AcceptButton = yourbutton;
All the best,
Martin
|
|
|
|
|
|
Hi,
and CancelButton is similar, it handles escape.
Luc Pattyn
|
|
|
|
|
ya
thank you
i have set the CancelButton = GoToCancelButton;
it is working thank you
With Regards
Prasad
|
|
|
|
|
Did you notice that CancelButton appears on Intellisense and the property grid at design time but AcceptButton doesn't appear on either both.
|
|
|
|
|
hi,
how to make form close whenever user press the Esc Button
Thank You
With Regards
Prasad
|
|
|
|
|
Forgive me if this has been covered somewhere before, but searching here for "COM Interface" or "COM Object" did not return anything interesting...
I have an out-of-proc COM server. It has been around for a little while and has been used by other (native) applications without issue. However, I now have a C#-based component using my server. When this happens, the memory requirements for my server start to climb at a rate that matches the times when the C# application is making periodic calls into the server. This is only being observed on two particular machines at a particular installation. The footprint can grow to more than 400MB(!) over its normal size of about 28-48MB.
The particular method being called returns data via out parameters. Actually, the method being called takes a series of VARIANT objects as in parameters and returns a series of VARIANT objects as out parameters, and different data can be returned depending on how the method was called. In this case, the data being returned is being returned as a BSTR -in-a-VARIANT .
This has never been an issue before. Oddly enough, this issue is not being reported anywhere else and cannot be recreated on my development system. I am thinking it may be connected to the C# code's memory management, because if that client disconnects (but remains running), the memory footprint slowly starts to reduce back to its normal size, making me think that that GC invocations are then taking place and recovering resources (the GC can also run at idle periods, not just on demand, right?). The COM server's implementation does not do anything with memory that would explain this, although I find it odd that the memory growth is being seen in the server and not the client. No performance impact is being observed, either.
Does anyone have any ideas as to why this may be happening? So far, this is the first .Net application that is using my server, and at the risk of sounding conceited, I have no reason to believe that the problem is on my end because of the past history of use with the server. Both the server's logging and examination under the debugger do not show any unnecessary allocations.
Has anyone experienced any strange memory-related behavior when working with an out-of-proc COM server? One special thing about this interface is that it uses a callback interface, which is optional. This particular C# client is not using the callback interface, passing the equivalent of a NULL interface pointer. This is an accepted use of the server.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
James R. Twine wrote: I am thinking it may be connected to the C# code's memory management
James R. Twine wrote: I have an out-of-proc COM server.
If your COM objects are holding session for clients memory use in the server is directly related to the client behavior, otherwise no.
led mike
|
|
|
|
|
The per-client memory that is allocated is being managed correctly. The reason I think it may have to do with GC activity is because the following has been observed:
1: When the C# portion of the application is made idle (or at least, more idle than normal), memory is slowly reclaimed.
2: If the other application is closed, the memory comes back much faster.
Another reason is because of how BSTRs have to be managed to pass them out-of-proc. When copies are made by the COM subsystem, where is that memory being tracked? If it is showing up in my process, because that is the "side" where it is being allocated, but it coorrelating BSTR on the client-side is not being freed until later on, would that cause what I am seeing?
This is the strangest thing...
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Hi..
In my application i have a situation where for particular period of time
specific no.of threads are created in SmartThreadPool..
And its working fine..
Now i want to dequeue some of the Thread items from the ThreadPool,
to stop the Threads..
I'm not sure how to get this..
Please help me..
For pooling i'm using SmartThreadPool.
thanks,
nas
|
|
|
|
|
I would like to create a new instance of a class, but I would like the user to tell me the name of the object they want to create, and the code uses that (stored as a string) name and creates the object.
This is done as a method. This is what I thought about, but it creates it called the name of the variable:
public void createTextBox(string textBoxName)
{
// Create a new text box
TextBox = textBoxName new TextBox;
}
I am going about this all wrong!
OK, what I want to do, is create a DLL, that is for a programming language created with C#, that allows them the make a GUI, they can create different components, how do I do this?
-- modified at 7:05 Wednesday 14th February, 2007
|
|
|
|
|
This is not possible, a variable name needs to be hard coded, but you can use an ArrayList to store an unkown number of TextBoxes.
|
|
|
|
|
This would be possible with a Dictionary<string,textbox>, in which case you can have a name associated with each created textbox. Just make sure you don't overwrite any existing values (with, for example, the ContainsKey() method).
Just out of curiosity, why do you want to have a textbox associated with a name?
Internet - the worlds biggest dictionary
|
|
|
|
|
I'm assuming that what you are asking is how can a user make a form dynamically by adding controls to it. To do this, you need to add items to the forms Control collection. If you want to see an example of this, just take a look inside a form you have created in Visual Studio.NET. Take a look inside the InitializeComponent method to see what needs to be done. (Note though, setting up a control is about more than just adding it to the collection. You need to set it's location, set it's name (and so on).)
If you have a control container (e.g. a Panel), then you would add any child controls of this to the controls Control collection.
I hope that this gives you enough of a hint about how to get started.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
hi every one
well my question is that I wanna validate a text box in a Windows application C# 2.0 so that the user doesnt enter a special character. If it blocks the entry of a special character right when the user is entering it, then that would be nice!
thanks in advance
Rocky
|
|
|
|
|
Use event KeyPress from the textBox and use this code:
This code means "t" is not allowed.
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 't')
{
e.Handled = true;
}
}
|
|
|
|
|
Hello,
You could handle the "KeyPress" event of your textbox instance, or better inherit your own textbox and override the protected OnKeyPress method.
Then you could do:
protected override void OnKeyPress(KeyPressEventArgs e)
{
string _allowedkeychars = "1234567890";
if (_allowedkeychars.IndexOf(e.KeyChar) < 0)
{
e.Handled = true;
return;
}
base.OnKeyPress (e);
}
private void YourTextBoxKeyPress(object sender, KeyPressEventArgs e)
{
string _allowedkeychars = "1234567890";
if (_allowedkeychars.IndexOf(e.KeyChar) < 0)
{
e.Handled = true;
return;
}
}
All the best,
Martin
|
|
|
|
|
yea that looks alot helpful to me. thanks alot Martin I appreciate this!
|
|
|
|
|
Hi, Actually I want to draw many rectangles on the screen and want to show all of them at once. Is there any function like BeginUpdate and EndUpdate in c#. so that the drawing process is not shown to the viewer.
|
|
|
|
|
No there isn't really, what you want is double-buffering, if you're using .NET 2 then there should be a DoubleBuffered property on the control you're inheriting from. If not then use base.SetStyle in the constructor of the class.
The BeginUpdate and EndUpdate are used in a different way, say you have a ListBox , if you want to add 1000 items to it normally each time you add an item the Invalidate method is called, this will cause the control to recalculate it's entire contents and redraw all of them. If you use the Begin/EndUpdate pair then what this does is set a flag to say that when an item is added / deleted changed it's not meant to be redrawn. When you call the EndUpdate function when all the items have been added then it calls the Invalidate method to redraw the control (and clears the flag).
You can see the obvious benefits, in the first method (no Begin/EndUpdate ) the control is redrawn 1000 times as each item is added (thus producing a flicker (unless you have an awesomely specced machine)), in the second it only redraws once when everything has finished.
|
|
|
|
|