|
I'm really confused.
I'm new to forms in c#, but i have used c# and forms before, just not together.
i want to draw a rectangle on the screen so i used this code in a button click event
Pen NewPen = new Pen(Color.Red,10);
Graphics g = this.CreateGraphics();
g.DrawRectangle(NewPen,200,200, 50,50);
this does exactly what i would expect, but it's not very interesting so i added some lines:
Pen NewPen = new Pen(Color.Red,10);
Graphics g = this.CreateGraphics();
int X = this.Width/2;
int Y = this.Height-100;
g.DrawRectangle(NewPen,X,Y, 50,50);
Now i don't get the rectangle, but if i step through the code i can see a flash as it gets drawn and then when the form is displayed it dissappears.
I revert to the original code and now that doesn't work either, but if i paste the code into a new project it works fine.
has anyone seen anything like this before?
I'm really confused, any help would be appreciated
russ
|
|
|
|
|
Perhaps you've turned double-buffered drawing on?
As a general rule, you shouldn't paint anything in response to a command. Instead, you should 'remember' (somehow) what needs to be painted, then paint it when Windows asks you to. Override the OnPaint method to handle this notification and do your painting.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
You have to override OnPaint (in a derivative class) or handle the Paint event (from a different class) and draw your rectangle based on some state variable (perhaps the Button.Click handler sets some variable to true, and your override for OnPaint draws a rectangle if that variable is true. If you don't, then each time the form (or any surface) is invalidated, your rectangle will disappear. So, in your form you'd do something like this:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
} Also, if you ever create a Graphics object or a Bitmap or something, dispose of it (i.e., call Dispose ) when you're done to release the native resources used by the class, otherwise you'll see a drop in performance after a while since memory isn't being freed (in some cases, not freed cast enough). Do not do this in the override for OnPaint or a Paint event handler, however - the caller will dispose the Graphics object when finished.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for the help, i'm putting it into the on_paint method.
i had realised that there was a painting issue going on, the cause of the confusion was the break point forcing a redraw of the form, but it took me a while to work that out.
for some reason i'd thought 2d drawing would take care of redraws etc by itself.
thanks again
russ
|
|
|
|
|
If i have a string like this :
string test = "<session> <appservers/> <parameters> <runtimestatistics>true" + "</runtimestatistics> <dateformat>dmy</dateformat> <sessionyearoffset>1980 " + "</sessionyearoffset> </propathwin32> <runprogram /> </parameters> <packages>"
Is it possible to check whether "runprogram", "parameters", "appservers" are in the string
With Indexof you can only check for one string: IndexOf("runprogram",0)
So i want to check whether several words are in a string
(actually i want to check whether my program can open the xml-file, so if those words are not in the xml-file then my program can't work)
Thx in advance
|
|
|
|
|
You could always load this string into an XmlDocument using the LoadXml method, or use a StringReader and then pass that to an XmlTextReader 's constructor overload.
However, a better way is to use XML in a way it's intended - using schemas. You should define a schema with a namespace and you can always validate if that XML document uses that namespace. If you can't change the schema, then simply use an XmlValidatingReader to read-in the XML document and embed a schema that matches the XML document structure you require. If the XML document doesn't validate against the schema, then don't use it.
Besides, nothing says you can't load the XML document to check what elements are present. If they aren't, don't continue to process the document. The XmlValidatingReader is the best way to go, however.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'd just add that the string isn't XML, but it is XML-like. Maybe the poster should first investigate the use of XML as a better solution to the problem at hand...
-Jeff
here, bloggy bloggy
|
|
|
|
|
I guess I didn't look that closely, but your right! Of course, it often seems that we aren't provided with full details on this forum to help answer questions. I just "love" it when someone provides no details and asks why something doesn't work!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm not saying you're wrong, just that I think maybe you should point the person to a good starting place for learning how to even use XML properly. They're pretty clearly going for XML, they're just not getting there.
-Jeff
here, bloggy bloggy
|
|
|
|
|
I wasn't implying that you said I was wrong, just making a statement that I didn't even notice it wasn't well-formed.
In any case, me a couple other people have given this guy plenty of information about XML. One can only do so much - the rest is up to the poster.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
If the words must occur in a specific order, a matching pattern can be specified with a regular expression.
You could make use of the Regex class ...
if (Regex.IsMatch(test, @"runprogram.*?parameters.*?appservers", RegexOptions.IgnoreCase)) ...
|
|
|
|
|
I created WinMainForm that setted IsMdiContainer=True and added toolBar to WinMainForm in MainProject (that compile to exe).
And I created WinParentForm in ParentProject (that compile to dll).
For example
public class WinMainForm : System.Windows.Forms.Form
{
...
private void openParent_Click(object sender, System.EventArgs e)
{
ParentProject.WinParentForm FormA = new ParentProject.WinParentForm();
FormA.MdiParent = this;
FormA.Show();
}
...
}
About that How can I control the toolBar (in MainProject.WinMainForm) from FormA (in ParentProject.WinParentForm) ?
|
|
|
|
|
If you're looking for an OLE-like way where the toolbar and/or menu updates depending on the current window (or other object), then you should use an interface that objects should implement with a method to pass either the main form's ToolBar or some other similar mechanism. This is more of a provider-based approach, which is far more common in commercial grade applications and is essentially what you see in applications like Microsoft Office and other ActiveX containers like Internet Explorer (which gains the Office buttons when an Active Document like Word Documents are opened inside it).
This also gives you an abstract designer so you don't have to use circular dependencies. Just define that interface in a common DLL that both projects reference (or even in the DLL project you already mentioned - just not in the EXE project since VS.NET can't reference an EXE assembly, even though the command-line compiler can).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Can you give me simple or demo project ?
|
|
|
|
|
It's not hard. This is what development is about - researching problems and solutions, designing the solution, and then writing the solution.
Simply define an interface, like IToolBarProvider which has a property or method that takes a ToolBar as a param. Your WinParentForm would implement this interface. WinMainForm - in an override to OnMdiChildActive for example - would reset the toolbar back to the default, determine if the child window class implements the interface, then passes the toolbar to the implementation for it to modify, something like this:
protected override void OnMdiChildActivate(EventArgs e)
{
base.OnMdiChildActivate(e);
IToolBarProvider tbProvider = ActiveMdiChild as IToolBarProvider;
if (tbProvider != null) tbProvider.ModifyToolBar(ToolBar tb);
} In a separate DLL project (or the one that already defines the MdiParentForm , define the interface like so:
public interface IToolBarProvider
{
void ModifyToolBar(ToolBar tb);
} It's a very simplistic example, but you should get the idea and explore it further.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there any kind of tutorial/source code/anything for C# similar to softwer on this link => http://fma.sourceforge.net
It's mobile phone controlling over your PC and other way around...
Any response is highly appreciated
|
|
|
|
|
If you want to know how what their source code looks like, browse their CVS repository[^] and write your own code. But why do what's already been done? It's GPL'd, so it's free software (as everything on SourceForge seems to be, though some licenses may be more restrictive).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
where do you get an add-in for Visual Studio Pro 2000?
I looked on MS website but didn't find a download... maybe I missed it..
Thanks
Will
|
|
|
|
|
An add-in for what?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
well I was trying to look at a project for Pocket PC and could not fined an emulator or add-in for VS Studio..
sorry for the blurry subject matter
will
|
|
|
|
|
VS.NET 2003 comes with the Compact Framework and I recommend that. If you can find it, the Compact Framework for .NET 1.0 beta (it was released for .NET 1.1) will work.
If you just want an emulator, though, you can download these from http://msdn.microsoft.com[^]. They also come as part of the Pocket PC 2002 and 2003 SDKs, IIRC.
You could always install the .NET Compact Framework into the ROM image (keep in mind this is a hardware emulator - not a software emulator - so it's better) and transfer files using the emulator support software. This allows you to use VS.NET 2002 (without the beta .NET CF) or the command-line tools (comes with the Framework, though the Framework SDK includes additional tools) to write an test mobile apps without having a physical PocketPC device.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thank you very much for the info
Will
|
|
|
|
|
OK, maybe I was bit lazy and looking for easier way to get whole picture ^_^. Thanks anyway Heath you're always coming to my aid it seems
c-ya
|
|
|
|
|
pekica wrote:
maybe I was bit lazy and looking for easier way to get whole picture
Sounds more like looking for the work done for you. It you really want to understand, studying it from another language you can't so easily translate or whatever will teach you far more since you'll actually have to research it instead of just copying and pasting. Would you agree?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yeah... but it will take me a lot more time to research. Nevermind I downloaded SDK and will look into it ^_^ if nothing else it'll remind me of good old Pascal times because of synatax .
c-ya
|
|
|
|