PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
Can't set font properly in designer on a custom control.
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
Can't set font properly in designer on a custom control.
![]() |
Can't set font properly in designer on a custom control. |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hi,
I'm working on a .NET CF project in C# (Visual Studio 2003). I authored 3 custom controls derived from ComboBox, CheckBox and TabControl and added them to my project. All they do is override the KeyDown method. (I used an MSDN article "Walkthrough: Authoring a Custom Control for Smart Device Applications" as a guide). Everything seemed to go smoothly. I can add and manipulate these controls in the designer. The problem that I'm having is that I can't set the font property on these controls in the designer (though I *think* everything else works ok). I can manually do so in the code. While debugging I noticed that the font that is read from the resources in InitializeComponent() is always the default Tahoma 10pt font, regardless of what is in the designer properties of the control. I looked in the resx file and the font settings seem wrong. The font 'Value' is blank rather than "Microsoft Sans Serif, 8.25". The font 'Type' is: System.Windows.Forms.Design.ResXNullRef, System.CF.Design, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a rather than something like: System.Drawing.Font, System.CF.Drawing, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a Entering the font name into the Value field doesn't help. Entering something different into the Type field doesn't help either. In this case it is immediately replaced with the (probably wrong) text. One clue is that I have the 'localizable' property set to true on all my forms. (at one point I was planning on using this, but have not as yet). If I create a test form with the 'localizable' property set to false then the font setting is never set at all in the designer code (InitializeComponent()), nor is the font property saved in the resx file. Again, though the designer claims the control is using 'Microsoft Sans Serif, 8.25", what get's used is actually 'Tahoma, 10". I would greatly appreciate any help or advice you might have to offer. I'm including the source code of one of my custom controls. Thankyou using System; using System.Data; using System.Windows.Forms; #if NETCFDESIGNTIME [assembly: System.CF.Design.RuntimeAssemblyAttribute("SmartControls,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null")] #endif namespace SmartControls { public class SmartComboBox : System.Windows.Forms.ComboBox { public SmartComboBox() { } /// <summary> /// Handles Keypad input. Uses the Bksp key to mimic the left arrow key. /// </summary> /// <param name="e"></param> protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e) { if ( e.KeyCode == Keys.Back ) { if ( this.SelectedIndex > 0 ) this.SelectedIndex--; e.Handled = true; } else { base.OnKeyDown (e); } } } } |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Try to add the ShouldSerializeFont method:
private bool ShouldSerializeFont() { return(!Font.Equals(defaultFont)); } -- Alex Yakhnin, .NET CF MVP www.intelliprog.com | www.opennetcf.org "Andrew" wrote: > Hi, > > I'm working on a .NET CF project in C# (Visual Studio 2003). I authored 3 > custom controls derived from ComboBox, CheckBox and TabControl and added > them to my project. All they do is override the KeyDown method. (I used an > MSDN article "Walkthrough: Authoring a Custom Control for Smart Device > Applications" as a guide). Everything seemed to go smoothly. I can add and > manipulate these controls in the designer. > > The problem that I'm having is that I can't set the font property on these > controls in the designer (though I *think* everything else works ok). I can > manually do so in the code. While debugging I noticed that the font that is > read from the resources in InitializeComponent() is always the default > Tahoma 10pt font, regardless of what is in the designer properties of the > control. > > I looked in the resx file and the font settings seem wrong. > > The font 'Value' is blank rather than "Microsoft Sans Serif, 8.25". > > The font 'Type' is: > System.Windows.Forms.Design.ResXNullRef, System.CF.Design, > Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a > rather than something like: > System.Drawing.Font, System.CF.Drawing, Version=7.0.5000.0, > Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a > > Entering the font name into the Value field doesn't help. Entering > something different into the Type field doesn't help either. In this case > it is immediately replaced with the (probably wrong) text. > > One clue is that I have the 'localizable' property set to true on all my > forms. (at one point I was planning on using this, but have not as yet). > > If I create a test form with the 'localizable' property set to false then > the font setting is never set at all in the designer code > (InitializeComponent()), nor is the font property saved in the resx file. > Again, though the designer claims the control is using 'Microsoft Sans > Serif, 8.25", what get's used is actually 'Tahoma, 10". > > I would greatly appreciate any help or advice you might have to offer. I'm > including the source code of one of my custom controls. > > Thankyou > > > > > using System; > using System.Data; > using System.Windows.Forms; > > #if NETCFDESIGNTIME > [assembly: > System.CF.Design.RuntimeAssemblyAttribute("SmartControls,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null")] > #endif > > namespace SmartControls > { > public class SmartComboBox : System.Windows.Forms.ComboBox > { > public SmartComboBox() > { > } > > /// <summary> > /// Handles Keypad input. Uses the Bksp key to mimic the left arrow > key. > /// </summary> > /// <param name="e"></param> > protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs > e) > { > if ( e.KeyCode == Keys.Back ) > { > if ( this.SelectedIndex > 0 ) > this.SelectedIndex--; > e.Handled = true; > } > else > { > base.OnKeyDown (e); > } > } > } > } > > > > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

