|
You could do something like this :
<br />
<br />
void Main(string[] args)<br />
{<br />
<br />
ArrayList ar = new ArrayList();<br />
ar.Add(5);<br />
ar.Add(2);<br />
ar.Add(6);<br />
ar.Add(5);<br />
ar.Add(8);<br />
ar.Add(9);<br />
ar.Add(1);<br />
ar.Add(1);<br />
ar.Add(9);<br />
ar.Add(5);<br />
RemoveDuplicates(ar);<br />
}<br />
<br />
void RemoveDuplicates(ArrayList ar)<br />
{<br />
ar.Sort();<br />
for (int i = ar.Count - 1; i > 0; i--)<br />
{<br />
if (ar[i].Equals(ar[i - 1]))<br />
{<br />
ar.RemoveAt(i);<br />
}<br />
}<br />
}<br />
---
"Drawing on my superior command of language I said nothing."
|
|
|
|
|
Hi,
I have write a simple application only to understand the Select command, but it doesn't work well.
In my application i have 3 button. When I click button 1 i disable button 1 and 2. When I click on button3 i reanable button 1 and 2 and want to select button 1 again.
The code (without the designer part) i wrote is the following:
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace WindowsApplication1<br />
{<br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
button1.Enabled = false;<br />
button2.Enabled = false;<br />
}<br />
<br />
private void button3_Click(object sender, EventArgs e)<br />
{<br />
button1.Enabled = true;<br />
button2.Enabled = true;<br />
button1.Select();<br />
}<br />
}<br />
}<br />
What should i do to solve this problem?
Best Regards
Ciao
Rudy Barbieri
|
|
|
|
|
It works. I didn't see any problem. After clicking button3, the selection is back to button1.
|
|
|
|
|
try to put other buttons on the from, put you code not in the first
buttons ...., it will not work
When you get mad...THINK twice that the only advice
Tamimi - Code
|
|
|
|
|
Use Focus instead of select
button1.Focus()
Saqib
|
|
|
|
|
how do i draw a point(x,y) on a form??
rzvme
|
|
|
|
|
Start your application, take a marker and set a dot on the screen...
Seriously though: look into the Graphics[^] class
|
|
|
|
|
Pretty easy.
1) Override the OnPaint method of your form.
2) This method gives access to PaintEventArgs which has a property named Graphics which you will use
3) You cant draw a point, but you can draw a rectangle with dimentions 1,1 - ie one pixel square at your given point (note the point will be the top right corner of your rectangle.
some code to get you started (untested, typed quickly)
using System.Drawing;
public override void OnPaint(PaintEventArgs e)
{
Point myPoint = new Point(20,20);
Graphiocs g = e.Graphics;
using(SolidBrush brush = new SolidBrusgh(Color.Black))
{
g.FillRectangle(brush,new Rectangle(myPoint, new Size(1,1) ));
}
}
|
|
|
|
|
|
I'm developing an windows application in .NET 2.0 where the user is supposed to navigate around the application using the arrow keys(I'm using KeyDown event to handle user key input).
My problem is that I want to use UserControls in my application but whenever I add my UserControls to my windows form the form don't recieve any KeyDown events when I press the arrows keys, however it reacts to any other keys being pressed!
Is this a bug and is there another way to do this?
Thanks
Vester
|
|
|
|
|
there is no such . you must be unable to handle event properly.elaborate more about your control's desired behaviour and what do you want
|
|
|
|
|
adfgh75 wrote:
My problem is that I want to use UserControls in my application but whenever I add my UserControls to my windows form the form don't recieve any KeyDown events when I press the arrows keys, however it reacts to any other keys being pressed!
The key press is probably being handled by another control. Have you tried setting KeyPreview[^]to true
|
|
|
|
|
Well yes, I have set KeyPreview to true on the form (and breakpoints to trace the event)and it still doesn't throw any KeyDown event when when I press the arrow keys, but it throws it when I press any other key. If I let the class inherit from Panel instead of UserControl or Control it works perfect.
However I've discovered that if I override the ProcessCmdKey() function in the form and process the key pressed there instead it will work.
.NET
|
|
|
|
|
Hi,
Can you please let me know what is wrong with the following if statement?
I believe the following values should make the statement to show the messagebox.
Do you agree?
Thanks
intPosHomeUS= -1
intPosHostUS= 7
intPosHomeUK= 7
intPosHostUK= -1
if (!(intPosHomeUS > 0 && intPosHomeUK > 0) || (intPosHomeUK > 0 && intPosHostUS > 0))
{
//show messagebox...
}
else
{
//print report...
}
|
|
|
|
|
no problem it should work fine
|
|
|
|
|
firstly I think youve made a typo (either in your code or in transposing it to a post)
fmardani wrote: if (!(intPosHomeUS > 0 && intPosHomeUK > 0) || (intPosHomeUK > 0 && intPosHostUS > 0))
should that be
if (!(intPosHomeUS > 0 && intPosHomeUK > 0) || (intPosHostUK > 0 && intPosHostUS > 0))
if not, and its correct, I could break down the code as
if(! (false && true) || (true && true))
breaks down further as
if( ! (false || true) )
and once more as
if(!true)
so
!true == false
so your message box will not show.
|
|
|
|
|
Doesn't it evaluate to:
(!false || true)
rather than
!(false || true)
Which would of course trigger the message box? I tend to go overboard with the parens just to make sure I'm negating the right thing because of stuff like this.
|
|
|
|
|
eggsovereasy wrote: I tend to go overboard with the parens just to make sure I'm negating the right thing because of stuff like this.
me too!
In my post I am assuming (rather than have tested) that it is evaluated as
!(false || true)
rather than
(!false || true)
|
|
|
|
|
The negation operator (!) has a higher precedence than the logical or operator. I think you made a typo yourself when you went from steps:
if(! (false && true) || (true && true))
To:
if( ! (false || true) )
Personally, I would suggest just using the debugger and putting a watch in to see what exactly is going in. Put the full statement "(!(intPosHomeUS > 0 && intPosHomeUK > 0) || (intPosHostUK > 0 && intPosHostUS > 0))" and then break it down into pieces to find the error.
As a side note, I'm not a big fan of putting a negation like that because it always seems to trip me up (may just be me). So, I typically pass the negation through the set...so you'd have something like this instead:
if (intPosHomeUS <= 0 || intPosHomeUK <= 0 || (intPosHostUK > 0 && intPosHostUS > 0))
It's just DeMorgan's Law...you can find more about it here[^].
|
|
|
|
|
Andrew Rissing wrote:
As a side note, I'm not a big fan of putting a negation like that because it always seems to trip me up (may just be me). So, I typically pass the negation through the set...so you'd have something like this instead:
It tends to trip me up as well, but I prefer writing the exression in the intuitive 'as english' format and either using a temp var for the base expression and then notting the temp in the expression or switching the then and else clauses around to avoid the negation all together.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
fmardani wrote: I believe the following values should make the statement to show the messagebox.
Yes, it should, and it does.
---
b { font-weight: normal; }
|
|
|
|
|
Is this a logic issue? I noticed that you're not checking for a value from intPosHostUK
|
|
|
|
|
Hi,
I need to know how can I create shotcut to myButton on form when I press key F10 independent of current active control on form, without using "ShortcutKey" in "ToolStipMenuItem".
I can do this if myButton is active control on form. I explicitly need to use key F10, so I can't use an & (ampersand) in a button text.
Thanks for help
|
|
|
|
|
handle key down or key up event of the form and then trigger click event by;
if(e.KeyCode == Keys.F10)
button1.PerformClick();
hope it helps.
Regards
Khalid
|
|
|
|
|
Hello,
And dont't forget to set:
this.KeyPreview = true;
All the best,
Martin
|
|
|
|