|
Hi,
you should manipulate the rectangle's coordinates in the KeyPress event (not KeyUp
or KeyDown) and call Invalidate;
and in the paint handler, you should draw the rectangle.
You wont need the myPen_del to undraw, since the paint handler will redraw
everything.
You may want to use doubleb-uffering to avoid or reduce flickering (see Form/Control
properties).
And you should choose more descriptive names for the rect's coordinates...
|
|
|
|
|
Thanks alot for ur answer, really helps me in some points... The coordinates will be renamed as soon as I got this problem behind me;)
Now the problem's still (as I think) that when I press a button to move the rectangle, it still will get stuck by changing the key pressed... I should really integrate a timer but there I'm really lost^^
|
|
|
|
|
Hi,
I dont really see the problem; when you press a key (say 'a') it generates one
KeyDown, one KeyUp and one KeyPressed. When you keep it down for a while it
autorepeats, i.e. it generates a number of KeyPressed events (same as in a
text editor such as MS Word; I am not sure it may also repeat the KeyDown,
but not the KeyUp). That could be sufficient.
If you want a faster repeat rate, I think you must provide it yourself; this
is how I would do it:
- create method doOneKey(Keys key) that does what that key should do
(including the Invalidate !)
- create a class member: private Keys lastKeyPressed
- in KeyDown do lastKeyPressed=e.KeyCode and call doOneKey(lastKeyPressed)
- create a Forms.Timer and let it tick continuously (say 100 msec)
- in timer tick handler call doOneKey(lastKeyPressed)
- in KeyUp do lastKeyPressed=Keys.None
- dont use KeyPress
You might want to also handle LostFocus event (so the move
stops when your Form loses focus)
BTW I have choosen the Forms.Timer because that one ticks on the GUI thread,
so it can not create concurrency problems (its tick does not get handled in
the middle of a key event).
Hope this helps
|
|
|
|
|
I think I just needed your last answer at least.. I'm just new to C# so I'm sometimes get confused although I should know the solution;) Thank you very very mutch!!
|
|
|
|
|
I try to set the condition for break point, but showing the error that condition is not correct.
I writr like Messageno == "ABC-001"
in condition textbox,
What is the correct way to set the condition?
Plz Guide me.
|
|
|
|
|
There are a couple of ways you can do it. First you can set the break point in the code behind. Then if you go to your break point window you can add a condition to the break point so it will only break when your condition is met. You can also use System.Dianostics.Debugger.Break to cause your code to break point. This only works if you have compiled in a debug mode.
Hope that helps.
Ben
|
|
|
|
|
Hello,
I am showing a form (MyForm) on some click event. I am having some buttons(Send, Get) on MyForm which are not mentioned as predefined event like OK or Cancel etc.
Still i want to know about the click event of the MyForm button.
I want
If(MyForm.ShowDialog() == DialogResult.Get)
{
}
How it can be implemented?????
Thanks..
Gajesh
|
|
|
|
|
Well, I would map the Get button to the OK result. Set the DialogResult for this button to OK. Then, you just need to check for DialogResult.OK.
|
|
|
|
|
You have to set the DialogResult property ycurselfe, before you close the form.
|
|
|
|
|
1st fire Send and Get button events with following code snippets:
btnSend.Click+=System.Windows.Forms.EventsArgs(...)
do same things for Get button.This will allow this event to occur.Now assign Get to Ok event of Dialog box.this will fire Get event when ok is clicked.
happy coding.
Regards
Chintan
www.visharadsoft.com
(Nothing is so purify as KNOWLEDGE)
|
|
|
|
|
Hi,
Very new to C#, and to .Net for that matter (been doing mainly legacy stuff for 20 years). Well, .Net is incredible, but one thing that bums me out is that I pretty much have to trash all the 3rd party component libraries that I have invested my money in over the years and essentially start over.
I've been perusing ComponentSource.com and ran across ComponentOne Studio Enterprise (http://www.componentsource.com/products/componentone-studio-enterprise/index.html). This is coming out of my personal funds, and $899 is *ouch*, but it seems to have just about everything to get a good start.
What do you all think? Any other suggestions to get some good components without making me broke?
Thanks to you all,
J Miller
|
|
|
|
|
What do you actually need the components for? While ComponentOne are good components, they cover both ASP.NET and WinForms. They also deal with reporting, grids and so on and so on.
I've tended to lean more towards DevExpress, and just picking the parts that I need rather than paying for everything. (You can also buy the components individually from ComponentOne).
For UI's, I'm currently using DevComponents. It's a very good product and Denis is continually updating it. Plus, with DevExpress and DevComponents, you can get the source code fairly inexpensively as well.
|
|
|
|
|
Pete, thanks for the great recommendations. What they offer is fastastic!
|
|
|
|
|
I would suggest since they are coming out of your personal funds you go with the DevExpress components. I know every once in a while they offer some of the components free, like their editor controls. DevExpress
|
|
|
|
|
does C# have any function or method that I can call to get the lon and lat from some reference I have with regards to the pic and a mouse position. Hope the questions is clear...
Thanks
Samuel
|
|
|
|
|
mercenary01 wrote: lon and lat
|
|
|
|
|
|
No, how could it ? It would need to know the starting position and the scale of the image. Even then, not all map images will have steady change of lat/lng.
You need to write your own code, based on what you know about the image you're displaying.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
man...that is what I thought, its tough
|
|
|
|
|
Yeah, it's always nicer to find stuff is supported for you, but in this case, I don't see any way it could take a bitmap and give lat/lng, and it should be pretty easy to work out, just find out the co-ords for the corners of your bitmap and do the math to track the rate of change to the mouse.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Dear all,
I am making a window form and using 1 datagridview control on it. The datagridview itself supports auto sort, but it is only valid with all column type except image column.
Please give me your all solutions on this issue.
Thanks.
Banana
|
|
|
|
|
from where you are retriving image name.Regardless of any source(s).Just do one thing might it work.Take all the image name(hope all r unique) and store them in array list.Now sort the list and store all column base on image name.
Regards
Chintan
www.visharadsoft.com
(Nothing is so purify as KNOWLEDGE)
|
|
|
|
|
Thanks Chintan.Desai for your reply.
My problem is really that when my datagridview load all data completely, click on each column, except image column, and every things are ok. But when i click on image column, it is not active.
If I put all my data in array list and each column use 1 array list, we will have many array lists. This is quite difficult for managing code.
Please send me your all other suggestions
Thanks for all help.
Banana
|
|
|
|
|
No buddy,Arraylist is one type of container,so store every image name in that arraylist and then use Sort function from array list class and sort them.
Regards
Chintan
www.visharadsoft.com
(Nothing is so purify as KNOWLEDGE)
|
|
|
|
|
Thanks Chintan for your warm and kind help.
I solved my problem by using IComparer interface. I have a object and image is one of its many properties, I wrote a lass for compare to object, and property used for compare is the image type (each product have 1 image type).And the last, I create an array list and sort all this array follows my new class which implements from IComparer.
<br />
public enum SortDirection<br />
{<br />
Ascending,<br />
Descending<br />
}<br />
class ElementSorting : IComparer<br />
{<br />
<br />
private SortDirection m_direction = SortDirection.Ascending;<br />
<br />
public ElementSorting() : base() { }<br />
<br />
public ElementSorting(SortDirection direction)<br />
{<br />
this.m_direction = direction;<br />
}<br />
<br />
int IComparer.Compare(object x, object y)<br />
{<br />
<br />
ABCElement elementX = (ABCElement)x;<br />
ABCElement elementY = (ABCElement)y;<br />
<br />
if (elementX == null && elementY == null)<br />
{<br />
return 0;<br />
}<br />
else if (elementX == null && elementY != null)<br />
{<br />
return (this.m_direction == SortDirection.Ascending) ? -1 : 1;<br />
}<br />
else if (elementX != null && elementY == null)<br />
{<br />
return (this.m_direction == SortDirection.Ascending) ? 1 : -1;<br />
}<br />
else<br />
{<br />
return (this.m_direction == SortDirection.Ascending) ?<br />
elementX.Type.CompareTo(elementY.Type) :<br />
elementY.Type.CompareTo(elementX.Type);<br />
}<br />
}<br />
}<br />
Thanks
Banana
|
|
|
|