I have an application with a main form and many dialogs. I want the main form and all of the dialogs to use the same icon in the forms' title bars. So, instead of defining the Icon property on each form, I have created an application resource and added a line of code to each Form_Load method.
First, add an Icon to your Project Resources (Project/Properties then on the Resource tab). Remember the name of the icon resource you create. Mine is AppIcon in this example.
Then for each Form_Load method in the VB.NET app (for the main form and each dialog's form), I add the following:
Me.Icon = My.Resources.AppIcon
There may be even better ways to do this, but this is the simplest I have found so far.
For more information on using resources, see:
http://visualbasic.about.com/od/usingvbnet/a/ResVBNET.htm
This blog is a depository for things I have found regarding VB.NET and C#.NET development (and other things I may need to remember). This blog is primarily for my own reference, but if the information I found is useful to others, then that is great. If others want to contribute with comments or other information, then that is great too.
Wednesday, July 30, 2008
Tuesday, July 29, 2008
Keeping a Nonmodal form on top of App, but not on top of Everything
It took me a while to figure this one out, but the solution is pretty simple.
I want to keep a nonmodal form on top of my main app form. I have tried using:
Dlg.TopMost = True
in the nonmodal form (Dlg), but this approach keeps the form on top of everything, not just my main app form.
The solution is:
Dlg.Owner = Me ' Me is the main app form
Dlg.TopMost = False
More info can be found at:
http://www.syncfusion.com/faq/windowsforms/faq_c95c.aspx#q975q
I want to keep a nonmodal form on top of my main app form. I have tried using:
Dlg.TopMost = True
in the nonmodal form (Dlg), but this approach keeps the form on top of everything, not just my main app form.
The solution is:
Dlg.Owner = Me ' Me is the main app form
Dlg.TopMost = False
More info can be found at:
http://www.syncfusion.com/faq/windowsforms/faq_c95c.aspx#q975q
Thursday, July 24, 2008
Changing a Control's Font Size at Runtime in VB.NET
If you have a control that is using a font with size 8.25 (which was defined at design-time), then at runtime you want to change it to a different size (such as 12), you cannot simply say:
ctrl.Font.Size = 12 (this will not work - Property Size is Read-Only)
However, you can replace the whole font:
ctrl.Font = new Font(ctrl.Font.FontFamily, 12, ctrl.Font.Style)
For more info and examples in C#, see: http://bytes.com/forum/thread261450.html
ctrl.Font.Size = 12 (this will not work - Property Size is Read-Only)
However, you can replace the whole font:
ctrl.Font = new Font(ctrl.Font.FontFamily, 12, ctrl.Font.Style)
For more info and examples in C#, see: http://bytes.com/forum/thread261450.html
Sunday, June 29, 2008
Using Brushes with Semi-Transparent Color
Filling a Rectangle, Ellipse, Shape, etc. with a semi-transparent fill is done by using a SolidBrush with a Alpha value somewhere between solid and transparent.
C#:
Color col = Color.FromArgb(75, 100, 100, 100);
SolidBrush b = new SolidBrush(col);
g.FillRectangle(b, 0, 0, this.Width - 1, this.Height - 1);
VB.NET:
Dim col As Color = Color.FromArgb(75, 100, 100, 100)
Dim b As New SolidBrush(col)
g.FillRectangle(b, 0, 0, Me.Width - 1, Me.Height - 1)
For better examples, go to this link:
http://www.java2s.com/Code/CSharp/2D-Graphics/Filledwiththesemitransparentandtransparentcolor.htm
C#:
Color col = Color.FromArgb(75, 100, 100, 100);
SolidBrush b = new SolidBrush(col);
g.FillRectangle(b, 0, 0, this.Width - 1, this.Height - 1);
VB.NET:
Dim col As Color = Color.FromArgb(75, 100, 100, 100)
Dim b As New SolidBrush(col)
g.FillRectangle(b, 0, 0, Me.Width - 1, Me.Height - 1)
For better examples, go to this link:
http://www.java2s.com/Code/CSharp/2D-Graphics/Filledwiththesemitransparentandtransparentcolor.htm
Labels:
Semi-Transparent Fill,
SolidBrush
Wednesday, June 18, 2008
Disappearing Controls in the Left SplitContainer Panel when using Large Fonts
I have been experiencing a strange problem that I have finally confirmed as a bug in the .NET Framework 2.0. If you are using a SplitContainter and place controls in your Left panel, then if you anchor those controls to the Right or the Bottom, they will disappear when you run the app on a machine that is using Large Fonts. My controls happen to all be in a group box, but I don't think that matters. The controls disappear because the anchor is setting the height and/or width to 0 and they are not visible. If you can drag the size wide or tall enough, the controls will start to appear, but they scaling is off and the anchor is not working correctly. If using Small Fonts, this problem does not exists.
I found a few other people with the same problem, but no solutions. I found one suggestion to do a Refresh on the Splitter move event, but this did not help me. My solution has been to adjust the size of the controls in the left panel myself and not rely on the anchor. Please post a comment if you have a better solution to this problem.
I found a few other people with the same problem, but no solutions. I found one suggestion to do a Refresh on the Splitter move event, but this did not help me. My solution has been to adjust the size of the controls in the left panel myself and not rely on the anchor. Please post a comment if you have a better solution to this problem.
Labels:
Anchor,
Large Fonts,
SplitContainer
Saturday, June 14, 2008
Setting BackColor to System Colors (like "Control")
It took a little searching to find out how to set the BackColor or ForeColor property of a control to the predefined colors you gets in the Visual Studio Properties window for BackColor's popup color setting on the System tab. For example, I want to set to the BackColor to the "Control" color.
I found this on:
http://bytes.com/forum/thread654472.html
control.BackColor = Color.FromKnownColor(KnownColor.Control)
I found this on:
http://bytes.com/forum/thread654472.html
Labels:
backcolor,
control,
forecolor,
KnownColor
Thursday, June 12, 2008
TechEd 2008 in Orlando
The TechEd 2008 Deveveloper’s Conference was in Orlando last week. I have always attended MEDC (Mobile and Embedded Developer’s Conference) before, but it has now been merged into TechEd. I believe that I prefer the more focused content of MEDC, but if my only way to get this information is to go to TechEd, then it is not too bad of an alternative. However, there were only 11 Windows Mobile session at TechEd 2008.
There is always a flavor to a Microsoft conference. I don’t know if this is directed by the powers that be or simply a natural alignment to the new features they are providing (or a combination of both). This year, the flavor definitely tastes of LINQ (Language Integrated Query). LINQ is undeniably an interesting concept that directly integrates SQL-like statement into the language syntax of any .NET language (VB.NET, C#, etc.). What makes this new feature somewhat interesting is that the SQL statements can be applied to data in arrays, enumerable objects, XML, and databases. So, the SQL way of querying a database can now be directly applied to data in your application, not just databases.
It also appears that most of the new language features we get from Visual Studio 2008 are directly related to LINQ: Anonymous Types, Extension Methods, Lambda Expressions, Implicitly typed locals, and Object Initializers. All of these new features were added just to support LINQ. One session on the Visual Studio 2008 IDE revealed that there wasn’t much added to the IDE because all of the developers were working on LINQ. On the downside, while LINQ does run on Windows Mobile, it will only work with your application data and does not work with SQL CE. There are a lot of things in the Compact Framework I would have rather had than a partially implemented version of LINQ.
While just about every session had to work LINQ in somehow, there were a couple of other technologies that were shown off. The Windows Presentation Manager (WPF) has developed a good deal since last year and can really produce some spectacular looking demos. The new support in Visual Studio 2008 for WPF is nice, but really seems to be early in its development. All of the WPF sessions seem to highlight a few points: it has great potential, it’s not here yet, and you will need a graphic designer to properly use it. A common phrase I heard in the session is “I’m not a graphic designer, so my WPF doesn’t look very good.” Nevertheless, I still found the Technology compelling enough to pursue. As an aside, Silverlight, which is an offshoot of WPF, came across as a very immature technology. Maybe it will mature quickly.
The Window Communication Foundation (WCF) was also a popular topic. It is just the extension of Web Services to what it probably should have been in the first place.
The Windows Workflow Foundation (WF, because WWF was already taken), was new to me and looks really interesting. An oversimplified description of it would be a project type in Visual Studio that lets you create a flow chart or diagram of your business logic and then can add the code behind the items in the diagram. The WF demos were compelling, but I have to question how well it really works in the real world. The demos used very simplistic logic. How well WF scales to a real application would be interesting to know. I think time will tell on this technology. It will become really popular or just disappear.
Another interesting thing about TechEd 2008 is what they didn’t talk about. Normally, these conferences are all using beta versions of something that hasn’t been released. I went to MEDC two years in a row and all they talked about was Whidbey (VS2005). Then it was all about Orcas (VS2008). With the exception of running VS2008 service pack 1 betas and a Silverlight beta, everyone was pretty content with the released software (quite a change from previous conferences). Does this mean there isn’t anything new in the queue or they are just taking a little longer to ramp up to the new stuff.
All and all, I was pretty pleased with the conference. Visual Studio 2008 looks good enough now to upgrade to (although I may wait until SP1 until I start upgrading all of my projects). Check out the full video and text of Bill Gates’ key: http://www.microsoft.com/presspass/exec/billg/speeches/2008/06-03teched.mspx
There is always a flavor to a Microsoft conference. I don’t know if this is directed by the powers that be or simply a natural alignment to the new features they are providing (or a combination of both). This year, the flavor definitely tastes of LINQ (Language Integrated Query). LINQ is undeniably an interesting concept that directly integrates SQL-like statement into the language syntax of any .NET language (VB.NET, C#, etc.). What makes this new feature somewhat interesting is that the SQL statements can be applied to data in arrays, enumerable objects, XML, and databases. So, the SQL way of querying a database can now be directly applied to data in your application, not just databases.
It also appears that most of the new language features we get from Visual Studio 2008 are directly related to LINQ: Anonymous Types, Extension Methods, Lambda Expressions, Implicitly typed locals, and Object Initializers. All of these new features were added just to support LINQ. One session on the Visual Studio 2008 IDE revealed that there wasn’t much added to the IDE because all of the developers were working on LINQ. On the downside, while LINQ does run on Windows Mobile, it will only work with your application data and does not work with SQL CE. There are a lot of things in the Compact Framework I would have rather had than a partially implemented version of LINQ.
While just about every session had to work LINQ in somehow, there were a couple of other technologies that were shown off. The Windows Presentation Manager (WPF) has developed a good deal since last year and can really produce some spectacular looking demos. The new support in Visual Studio 2008 for WPF is nice, but really seems to be early in its development. All of the WPF sessions seem to highlight a few points: it has great potential, it’s not here yet, and you will need a graphic designer to properly use it. A common phrase I heard in the session is “I’m not a graphic designer, so my WPF doesn’t look very good.” Nevertheless, I still found the Technology compelling enough to pursue. As an aside, Silverlight, which is an offshoot of WPF, came across as a very immature technology. Maybe it will mature quickly.
The Window Communication Foundation (WCF) was also a popular topic. It is just the extension of Web Services to what it probably should have been in the first place.
The Windows Workflow Foundation (WF, because WWF was already taken), was new to me and looks really interesting. An oversimplified description of it would be a project type in Visual Studio that lets you create a flow chart or diagram of your business logic and then can add the code behind the items in the diagram. The WF demos were compelling, but I have to question how well it really works in the real world. The demos used very simplistic logic. How well WF scales to a real application would be interesting to know. I think time will tell on this technology. It will become really popular or just disappear.
Another interesting thing about TechEd 2008 is what they didn’t talk about. Normally, these conferences are all using beta versions of something that hasn’t been released. I went to MEDC two years in a row and all they talked about was Whidbey (VS2005). Then it was all about Orcas (VS2008). With the exception of running VS2008 service pack 1 betas and a Silverlight beta, everyone was pretty content with the released software (quite a change from previous conferences). Does this mean there isn’t anything new in the queue or they are just taking a little longer to ramp up to the new stuff.
All and all, I was pretty pleased with the conference. Visual Studio 2008 looks good enough now to upgrade to (although I may wait until SP1 until I start upgrading all of my projects). Check out the full video and text of Bill Gates’ key: http://www.microsoft.com/presspass/exec/billg/speeches/2008/06-03teched.mspx
Labels:
TechEd 2008
Subscribe to:
Posts (Atom)