Here is the code necessary to reproduce the bug.
- Create a WinForm project
- Copy/paste C# code in Program.cs file
- Create a .xoml WPF control
- Copy code the XAML code in it
- Add necessary references
- Run the code
You will see that;
ONE : if you resize the form, making it bigger, the character auto resizing feature is not well suited as the character height is never the proper one regarding of the digital gauge height;
TWO : if you resize the form very small you'll get a Negative Height argument exception.
A good auto resize feature is really important for me because my application will be deployed on different targets with many different screen resolutions. I need to rely on a good resizing treatment, as good as the one one can find in circular gauges for examples, by the use of %.
Thank you.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace test {
static class Program {
/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public partial class DigitalGauge : System.Windows.Controls.UserControl {
public DigitalGauge() {
InitializeComponent();
}
}
public class Form1 : Form {
public Form1() {
InitializeComponent();
elementHost1.Child = new DigitalGauge();
}
/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
/// <param name="disposing">true si les ressources managées doivent être supprimées ; sinon, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent() {
this.elementHost1 = new System.Windows.Forms.Integration.ElementHost();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// elementHost1
//
this.elementHost1.Dock = System.Windows.Forms.DockStyle.Fill;
this.elementHost1.Location = new System.Drawing.Point(3, 3);
this.elementHost1.Name = "elementHost1";
this.elementHost1.Size = new System.Drawing.Size(95, 46);
this.elementHost1.TabIndex = 0;
this.elementHost1.Text = "elementHost1";
this.elementHost1.Child = null;
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Controls.Add(this.elementHost1, 0, 0);
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(203, 105);
this.tableLayoutPanel1.TabIndex = 1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(322, 207);
this.Controls.Add(this.tableLayoutPanel1);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.Name = "Form1";
this.Text = "Form1";
this.tableLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Integration.ElementHost elementHost1;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
}
}
<UserControl x:Class="test.DigitalGauge"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"
Height="170" Width="348" xmlns:gauge="http://schemas.actiprosoftware.com/winfx/xaml/gauge" Background="Transparent">
<gauge:DigitalGauge x:Name="gauge" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Value="0"
CharacterCount="10" Foreground="Cyan" Background="Black" CharacterPadding="10,0" BackgroundType="RoundedRectangleLightGradient"
RimType="RoundedRectangleLightGradient" CharacterType="DotMatrix5By7Rectangle" GlassType="RoundedRectangle">
</gauge:DigitalGauge>
</UserControl>
[Modified at 03/11/2011 07:57 AM]
[Modified at 03/11/2011 07:59 AM]
[Modified at 03/11/2011 08:00 AM]