|
C# and C++ have the same syntax. You can use it in C# too.
if(done)
break;
is correct for both.
Mazy
No sig. available now.
|
|
|
|
|
Visual Studio .NET considers the code to be an error:
Cannot implicitly convert type 'int' to 'bool'
|
|
|
|
|
You didn't say it returns int value. Cast it too bool.
if((bool)done)
...
Mazy
No sig. available now.
|
|
|
|
|
well the casting still throws up the same error
Cannot convert type 'int' to 'bool'
any hoo.
what number does done have to be for it to satisfy the condition?
|
|
|
|
|
So use If(done==1) .It returns error too?
Mazy
No sig. available now.
|
|
|
|
|
more like while(true)
break;
its not a full int world anymore
|
|
|
|
|
zoltan_ie wrote:
It been a long time since i've done C++ but what is the correct statement in C#?
???
if(1 == done)
break;
if(0 != done)
break;
???
Use above lines, no problem
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
oh my god, i'm gonna go ape sh*t!
if(done)
do1
else
do2
what number does done have to be to do1?
In C what number does done in the if statement have to be to give a true condition
|
|
|
|
|
I think if done is 0 then (bool )done is false otherwise it's true.
but, why don't you use bool data type?
private bool <code>done</code>;
done = true;
if(<code>done</code>)
do1;
else
do2;
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Lesson learnt from Perl:
It is easier to define "false" than "true": 0 (zero) and null are "false", everything else is true.
Olorin,
YAPPTH
|
|
|
|
|
int done;
...
if (Convert.ToBoolean(done))
break;
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
Why keep it an int at all?
bool done = false;
...
if( done )
break; C doesn't have a concept of a boolean so you had to use some other data type to represent one, most code uses an int to hold a boolean value. C++ has bool datatype, but since the Win32 API is C based you typically don't use it favoring an int or the #defined BOOL .
Like C++, C# has a bool data type, unlike C++ though there isn't any legacy code to be aware of so you should use it whenever necessary.
[edit]And unlike C/C++, the bool datatype has a true/false value instead of a non-zero/zero value. So you need to assign true to done instead of a 1.
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
The suggestion above to use a bool is the best.
The suggestion to cast the int to a bool is silly.
By definition, a int is "true" if it does NOT equal zero. Thus you should always test against the false situation. The correct syntax of your two choices is:
if (0 != done)<br />
break;
This syntax should also be used in C# (if you don't use bool.)
|
|
|
|
|
how to detect that I just press Ctrl+Key
I was try with code :
<br />
privated void myInput_KeyDown(object sender,KeyEventArgs e)<br />
{<br />
if (e.KeyCode==(Keys.G & Keys.Control)<br />
{<br />
}<br />
}<br />
but It not run
please help me, thanks
|
|
|
|
|
Can anyone show me how to fill this figure with a blue color?
System.Drawing.Graphics formGraphics = null;
System.Drawing.Pen myPen;
formGraphics = pictureBox7.CreateGraphics();
myPen = new System.Drawing.Pen(System.Drawing.Color.Black,1);
formGraphics.DrawLine(myPen, 4, 4, 50, 4);
formGraphics.DrawLine(myPen, 4, 4, 4, 100);
formGraphics.DrawLine(myPen, 50, 4, 50, 100);
formGraphics.DrawLine(myPen, 4, 100, 27, 120);
formGraphics.DrawLine(myPen, 50, 100, 27, 120);
Maybe with the FillPolygon method.
|
|
|
|
|
Point[] points = {
new Point(4, 4),
new Point(50, 4),
new Point(50, 100),
new Point(27, 120),
new Point(4, 100),
new Point(4, 4)};
SolidBrush brush = new SolidBrush(Color.Blue);
e.Graphics.FillPolygon(brush, points, FillMode.Alternate);
e.Graphics.DrawLines(myPen, points);
|
|
|
|
|
WiB:
Thanks. It works perfekt.
How do you know in which order to put the Points??
Eks:
Point[] points = {
new Point(4, 4),
new Point(50, 4),
new Point(50, 100),
new Point(27, 120),
new Point(4, 4),
new Point(4, 100)};
Won't fill the figure correkt.
|
|
|
|
|
Because there is a rule:
You put points in the same order like it would be if you draw figure by hand without break:
you start from first point in array, draw line until second, after draw line from second point to third and so on to the last point.
And normally I start and finish points array with the same point, but it's not allways necessary.
|
|
|
|
|
|
WiB:
Is it possible to make the mouse cursor = Cursors.Hand
if the the user point the mouse inside my figure ?
formGraphics.DrawLine(myPen, 4, 4, 50, 4);
formGraphics.DrawLine(myPen, 4, 4, 4, 100);
formGraphics.DrawLine(myPen, 50, 4, 50, 100);
formGraphics.DrawLine(myPen, 4, 100, 27, 120);
formGraphics.DrawLine(myPen, 50, 100, 27, 120);
|
|
|
|
|
1). In OnPaint :
Point[] points = {
new Point(4, 4),
new Point(50, 4),
new Point(50, 100),
new Point(27, 120),
new Point(4, 100),
new Point(4, 4)};
GraphicsPath path = new GraphicsPath();
path.AddLines(points);
Region reg = new Region(path);
bounds = reg.GetBounds(e.Graphics);
2). Override OnMouseMove method as follow:
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
{
if (bounds.Contains(e.X, e.Y))
this.Cursor = Cursors.Hand;
else this.Cursor = Cursors.Default;
base.OnMouseEnter(e);
}
RectangleF bounds is global
This is if you want to draw a shape on a form.
If your shape is a control on the form, you should do it by another way.
PS: Because variable bounds you inisialize only once, you should do it, for example, in constructor or you may keep it in OnPaint but make sure that you initialize it once (performance!).
"...hasn't really been well accepted ... as the ratings tell us so far " - Nishant S
|
|
|
|
|
I'm am developing a user control with some properties in it. Some of these properties, I only want them to be accessible in codes, and not visible in the property window when the control is added to the form.
For Example, if I have a property Name , this:
Control.Name
is ok, but I don't want the Name property visible in the Property Window
Does anyone have any ideas on how to achieve this? Any help would be welcome.
Nick Seng (the programmer formerly known as Notorious SMC)
God, I pity me! - Phoncible P. Bone
|
|
|
|
|
Put this above your property:
[Browsable(false)]
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I found the solution 10 minutes after I posted that. That'll teach me to stop giving up so fast.
But thanks on the prompt answer.
Nick Seng (the programmer formerly known as Notorious SMC)
God, I pity me! - Phoncible P. Bone
|
|
|
|
|
Hello,
Suppose to have a 4 processors system.
It is better to have 32 working threads or 8 groups of 4 working threads to do the same job.
In the first case I can ignore the number of processors because the work it is splitted equally on everyone. In the second I have to take care of it but maybe the OS is less involved in continually switching from thread to thread...
Any other consideration to help me decide?
Thanks a lot,
Alberto Bencivenni
www.devDept.com
|
|
|
|
|