|
I'd do it right myself, and then not have to worry. And I wouldn't bother to declare a variable called 'now'.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
>> And I wouldn't bother to declare a variable called 'now'.
lol! Quite right. The example was slightly contrived from the original, where the variable was justified, because it was used in several places.
|
|
|
|
|
I absolutely would never do this kind of optimization.
Yes, always trust the compiler. Only optimize algorithms - that's the way I do it and it saves quite a bit of worrying
|
|
|
|
|
The stack frame does not change when you declare variables. The stack frame is created when the method is called, and allocates space for all variables used in the method.
The only difference if you move the declaration is that the scope of the variables change. The space for the variables is still allocated the same way.
I always keep the declaration of the variables separate from the code. This is a practice that I got from Pascal programming. (In Pascal the variable declaration is even placed outside the actual procedure body.) I think that it makes the code clearer, and it actually more closely resembles what is actually happening when the code is executed.
---
b { font-weight: normal; }
|
|
|
|
|
I have drawn a Rectangle and corresponding X and Y axes with tick marks.
I would now like to number the tick marks on each tick in the range of
-9 to +9. Not sure of an efficient way to attack the problem. Any ideas?
many thanks...;)
|
|
|
|
|
A forloop and DrawString, I would have thought...
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm writting an app that I hope to sell and develope into an enterprise type app. It came to my attention that I should have all my data access in a DAL along with my business objects. So my question is at what point is it necessary to implement a DAL and business object layer as to just writting a class for data access and keeping your business objects in your main app class?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Tom Wright wrote:
So my question is at what point is it necessary to implement a DAL and business object layer as to just writting a class for data access and keeping your business objects in your main app class?
Now. You should always do your business tier in a seperate dll, and your data access in another seperate dll. The reason is simple, it forces you to keep these layers seperate, which makes it easier to replace any layer if you ever need to, and to encapsulate your code in logical components.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
I was hoping you could help me with a problem I'm having. I am writing a .DLL that reorders and renames a folder of images using System.Drawing.Image and System.IO. The .DLL is called from a Windows form, which catches events as the .DLL processes each file. I'd like the Windows application to show the image that is currently being processd.
My solution has been to create an event that is triggered as each new image is identified, passing the image out. I cannot just pass out the actual image, as the calling application's picture box would lock the image so it couldn't be moved etc by the .DLL.
What I have done instead is to redraw the image as a smaller bitmap (to the dimensions of the picturebox), this works in as much as it doesn't lock the file, but the picture box is blank (though there is a bitmap being passed, according to the Auto dialog).
I've checked my bitmap code in a seperate application that doesn't rely on an external .DLL and it works.
I've successfully passed strings and integers out, that have then appeared in the appication.
I'd like to know if I'm doing this the best way and where I am going wrong, cheers!
Bitmap conversion code in .DLL, DoNextFile is the trigger.
System.Drawing.Image img = System.Drawing.Image.FromFile(sour_file);<br />
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(144, 108);<br />
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);<br />
g.DrawImage(img, 0, 0, 144, 108);<br />
<br />
DoNextFile(bmp);
Creation of the Trigger in .DLL
public delegate void NextFile (System.Drawing.Image img);<br />
public event NextFile Next;<br />
<br />
private void DoNextFile(System.Drawing.Image img)<br />
{<br />
if (Next!=null)<br />
Next(img);<br />
}
Catch code in Windows app.
public void CatchNextFile (System.Drawing.Image img)<br />
{<br />
if (pbxFile != null)<br />
{<br />
pbxFile.Dispose();<br />
}<br />
pbxFile.Image = img;<br />
this.Update();<br />
}
|
|
|
|
|
Well, you are Disposing of the picturebox... perhaps you meant pbxFile.Image.Dispose()?
|
|
|
|
|
If it's that easy I'm not sure but I might cry...
|
|
|
|
|
Thank you for your help, I can't believe I made such a mistake.
Thanks again.
|
|
|
|
|
I'm reading text data from an xml file where there are potential newlines embedded into the string, but in some places I need to display the full text on a single line. Whenever I doso however I get to of the empty blocks used as placeholders for unprintable chars.
The xml data looks like this:
<comment>line one
line two</comment>
after reading it into a string (indirectly using the xml classes (we're using encapsulated versions that hide the ugly details)) I've tried both of the following unsuccessfully to remove the newlines.
s.Replace("\n"," ");
s.Replace(Environment.NewLine," ");
|
|
|
|
|
Strings are immutable
s = s.Replace(Environment.NewLine, "");
|
|
|
|
|
Woops, I knew that. :-/
Would've been nice if the compiler gave a warning though.
|
|
|
|
|
Hi everyone,
Is there an event like Form.Resize that is raised only after the user has finished resizing the form, i.e., when the mouse button is released at the end of the resize operation?
Thanks
|
|
|
|
|
I would imagine that it would be the Form_OnPaint() method.
|
|
|
|
|
But that not specific to resizing. The Paint event fires every time the form is being redrawn, for example when you move other applications over it. I'm looking for something that signals a resize, but that would fire AFTER, not WHILE the resize is taking place.
Thanks
|
|
|
|
|
I believe the short answer is no.
You can use the SizeChanged() event which fires AFTER every size change, but not after the mouse has been released. Normally you would want this to happen anyway so that you get the 'smooth' resize effect.
Using a combination of SizeChanged() and MouseUp() events won't work because the MouseUp() event isn't "Mousing-up" on the form. It is "Mousing-up" on the resize handle.
Unfortunately using OnPaint() won't work either.
Is there a specific reason why you need it after the mouse has been released?
|
|
|
|
|
Thanks. I'm not interested in the mouse release per se, I just want to refresh the form only once when the user drags the corner of the window, and not update it continuously while it's being resized, which causes flicker.
Thanks, maybe SizeChanged would work.
|
|
|
|
|
Flickering effects is a common problem to user controls. I'm not sure if this fits your situation (as I've only used it for controls), but it may help.
For user controls, setting Control.SetStyle to ControlStyles.DoubleBuffer and ControlStyles.AllPaintingInWmPaint will paint to an off-screen bitmap first. In your case you could try this.SetStyle.
I found this web site helpful:
http://pluralsight.com/wiki/default.aspx/Craig/FlickerFreeControlDrawing.html[^]
|
|
|
|
|
Even with double buffering, if one of your controls was sufficiently timeconsuming to redraw delaying redraw until the end of the resize would be useful. One untested idea about how to do that would be to have the SizeChanged event disable OnPaint and start a thread with a timer to reenable it after X time, with each call of SizeChanged resetting the timer.
|
|
|
|
|
hello
i have a problem regarding button handling. if i want to click a button1 and want that a variable value is set to like 4 after that button i must have to click second button and another variable value is set to like 5 then when i click ok button a function will be called and pass these variable values to a function. how will i implement this problem and can i return a value form a button function if yes then how please tell through sample code or simple statements thanks
|
|
|
|
|
That's just elementary C# coding. Create a form. Add a set of buttons (1, 2, 3, etc.) Write a click handler event
private void ButtonClickHandler(object sender, EventArgs args)
{
Button which = (Button) sender;
input += which.Text;
}
In the property grid you switch over to the event view and assign this handler method to all of your buttons. You may want an Enter key on the form as well....that way people can enter more than a single digit to feed the function. So then you'd double click the Enter click event which will automatically create an event handler foryou and you can add the following code:
private void Enter_Click(object sender, EventArgs args)
{
if (variableA == null) {variableA = input; input = string.Empty;}
else {variableB = variableA; variableA = input;}
}
when you click the function button you just do
CallFunction(variableA, variableB)
Now if you cannot solve your problem with what I've given you, then I highly recommend you start taking developer classes.
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
I am developing an app on a laptop, using VS and C# 2003. The app will run on a tablet PC in portrait mode.
How can I develop the app on my laptop for a 760X1024 orientation when VS won't allow it (the 1024 height setting always jumps down to 812). the tablet sdk 1.7 doesn't seem to have anything for this. Is there a workaround?
|
|
|
|