Closed neoxeo closed 1 year ago
You can't create Font with Control.DefaultFont.ToString() as a first parameter. You need to pass there a FontFamily or Font name. ToString returns not only name but other additional info.
Color class has static color properties for all standard colors. I beleive I could add some additional method to enum them, will think about it.
If you want to change size of the control, use Bounds property. I will add some example on how to do it. Currently Size, Width ande Height properties are something like default size. and not the current size.
I will try to add four additional controls for the button sample as you did and will check how everything works.
Here is my code for button if you want. This is a work in progress so some things need to be fixed :
using Alternet.UI;
using System;
using System.Drawing;
using System.Drawing.Text;
namespace ControlsSample
{
internal partial class ButtonPage : Control
{
private IPageSite? site;
public ButtonPage()
{
InitializeComponent();
// put all labels to Bold
labelText.Font = new Alternet.Drawing.Font("Arial", 8, Alternet.Drawing.FontStyle.Bold);
labelFonts.Font = new Alternet.Drawing.Font("Arial", 8, Alternet.Drawing.FontStyle.Bold);
labelSize.Font = new Alternet.Drawing.Font("Arial", 8, Alternet.Drawing.FontStyle.Bold);
labelColor.Font = new Alternet.Drawing.Font("Arial", 8, Alternet.Drawing.FontStyle.Bold);
labelBackColor.Font = new Alternet.Drawing.Font("Arial", 8, Alternet.Drawing.FontStyle.Bold);
// test to change background color of button
//button.Background = Alternet.Drawing.Brushes.AliceBlue;
// load content of combobox
comboBoxSize.BeginUpdate();
try
{
int j = 2;
for (int i = 0; i < 6; i++)
{
comboBoxSize.Items.Add(j);
j = j + 2;
}
var fnts = FontFamily.Families;
foreach (var fnt in fnts)
{
comboBoxFonts.Items.Add(fnt.Name);
}
}
finally
{
comboBoxSize.EndUpdate();
}
ApplyText();
ApplyDisabled();
ApplyImage();
ApplyDefault();
}
public IPageSite? Site
{
get => site;
set
{
site = value;
}
}
private void TextTextBox_TextChanged(object sender, Alternet.UI.TextChangedEventArgs e)
{
ApplyText();
}
private void ApplyText()
{
button.Text = textTextBox.Text;
}
private void DisabledCheckBox_CheckedChanged(
object? sender,
System.EventArgs e)
{
ApplyDisabled();
}
private void BoldCheckBox_CheckedChanged(
object? sender,
System.EventArgs e)
{
UpdateButtonText();
}
private void ApplyDisabled()
{
button.Enabled = !disabledCheckBox.IsChecked;
}
private void ImageCheckBox_CheckedChanged(object sender, System.EventArgs e)
{
ApplyImage();
}
private void ApplyImage()
{
if (button == null)
return;
button.StateImages = imageCheckBox.IsChecked ? ResourceLoader.ButtonImages : new ControlStateImages();
}
private void DefaultCheckBox_CheckedChanged(object sender, System.EventArgs e)
{
ApplyDefault();
}
private void ApplyDefault()
{
button.IsDefault = defaultCheckBox.IsChecked;
}
private void Button_Click(object sender, System.EventArgs e)
{
site?.LogEvent("Button: Click");
}
private void ComboBoxSize_SelectedItemChanged(object? sender, EventArgs e)
{
UpdateButtonText();
site?.LogEvent($"ComboBoxSize: SelectedItemChanged. SelectedIndex: {(comboBoxSize.SelectedIndex == null ? "<null>" : comboBoxSize.SelectedIndex.ToString())}");
}
private void ComboBoxFonts_SelectedItemChanged(object? sender, EventArgs e)
{
UpdateButtonText();
site?.LogEvent($"ComboBoxSize: SelectedItemChanged. SelectedIndex: {(comboBoxFonts.SelectedIndex == null ? "<null>" : comboBoxFonts.SelectedIndex.ToString())}");
}
private void ComboBoxColors_SelectedItemChanged(object? sender, EventArgs e)
{
UpdateButtonText();
site?.LogEvent($"ComboBoxColors: SelectedItemChanged. SelectedIndex: {(comboBoxColors.SelectedIndex == null ? "<null>" : comboBoxColors.SelectedIndex.ToString())}");
}
private void ComboBoxBackColors_SelectedItemChanged(object? sender, EventArgs e)
{
UpdateButtonText();
site?.LogEvent($"ComboBoxBackColors: SelectedItemChanged. SelectedIndex: {(comboBoxBackColors.SelectedIndex == null ? "<null>" : comboBoxBackColors.SelectedIndex.ToString())}");
}
private void UpdateButtonText()
{
double size = 10;
if (comboBoxSize.SelectedItem != null)
{
size = Convert.ToDouble(comboBoxSize.SelectedItem);
}
if (comboBoxFonts.SelectedItem != null)
{
if (boldCheckBox.IsChecked)
button.Font = new Alternet.Drawing.Font(comboBoxFonts.SelectedItem.ToString(), size, Alternet.Drawing.FontStyle.Bold);
else
button.Font = new Alternet.Drawing.Font(comboBoxFonts.SelectedItem.ToString(), size, Alternet.Drawing.FontStyle.Regular);
}
else
{
if (boldCheckBox.IsChecked)
button.Font = new Alternet.Drawing.Font(Control.DefaultFont.ToString(), size, Alternet.Drawing.FontStyle.Bold);
else
button.Font = new Alternet.Drawing.Font(Control.DefaultFont.ToString(), size, Alternet.Drawing.FontStyle.Regular);
}
}
}
}
And uixml code :
<Control x:Class="ControlsSample.ButtonPage"
xmlns="http://schemas.alternetsoft.com/ui/2021"
xmlns:x="http://schemas.alternetsoft.com/ui/2021/uixml"
xmlns:local="clr-namespace:ControlsSample;assembly=ControlsSample">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" Padding="10" Grid.Column="0">
<Label Text="Text: " Name="labelText" />
<TextBox Text="Test Button" Name="textTextBox" Margin="0,3,0,0" TextChanged="TextTextBox_TextChanged"/>
<CheckBox Text="Disabled" Name="disabledCheckBox" CheckedChanged="DisabledCheckBox_CheckedChanged" Margin="0,10,0,0" />
<CheckBox Text="Image" Name="imageCheckBox" CheckedChanged="ImageCheckBox_CheckedChanged" Margin="0,10,0,0" IsChecked="True" />
<CheckBox Text="Default" Name="defaultCheckBox" CheckedChanged="DefaultCheckBox_CheckedChanged" Margin="0,10,0,0" />
<CheckBox Text="Bold" Name="boldCheckBox" CheckedChanged="BoldCheckBox_CheckedChanged" Margin="0,10,0,0" />
<Label Text="Text Font" Name="labelFonts" Margin="0,20,0,0"/>
<ComboBox Width="25" Name="comboBoxFonts" IsEditable="false" Margin="0,3,0,0" SelectedItemChanged="ComboBoxFonts_SelectedItemChanged" />
<Label Text="Text Size" Name="labelSize" Margin="0,10,0,0"/>
<ComboBox Width="5" Name="comboBoxSize" IsEditable="false" Margin="0,3,0,0" SelectedItemChanged="ComboBoxSize_SelectedItemChanged" />
<Label Text="Text Color" Name="labelColor" Margin="0,10,0,0"/>
<ComboBox Width="25" Name="comboBoxColors" IsEditable="false" Margin="0,3,0,0" SelectedItemChanged="ComboBoxColors_SelectedItemChanged" />
<Label Text="BackGround Color" Name="labelBackColor" Margin="0,10,0,0"/>
<ComboBox Width="25" Name="comboBoxBackColors" IsEditable="false" Margin="0,3,0,0" SelectedItemChanged="ComboBoxBackColors_SelectedItemChanged" />
</StackPanel>
<GroupBox Title="Button" Grid.Column="1" Margin="10">
<Button Width="130" Name="button" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="10" Click="Button_Click"/>
</GroupBox>
</Grid>
</Control>
I have studied uixml that you provided. In general, this is not a good approach to set Width of the combobox to some specific value. That's because width of the combobox button on different operating systems is different. Also fonts are different. So we actually do not know what width is right. It is better to allow automatical width which will grow to the largest combobox width in the group. I am adding 4 comboboxes to the Button sample page and let you know when it is published to Master, so you could check how it is done.
@neoxeo, I have uploaded to Master updated Button page in ControlsSample with 4 new comboboxes. Please let me know if you have any other questions on this issue.
@generalloki Thanks for these informations. I understand now the reason. I'm not at home, I will test new comboboxes tomorrow. Thanks a lot for your job !
@generalloki, this is perfect ! Thanks Default checkbox have no effect. Necessary to keep it ? I think yes? It can be used to "reset" all values of comboboxes to Empty and have a button like it was before changes.
Default checkbox shows how Button is painted in Default Dialog Button style. So it is needed like it is now. I am closing this issue for now as it seems we clarified everything.
@generalloki, sorry, I don't understand. If I change Font or Size or ... and after I check the Default checkbox, nothing happened. Button is Not painted in Default Dialog Button style.
When I click on the Default checkbox, button border becomes blue.
@neoxeo , I change Font or Size and click on Default checkbox, button is painted with blue border as expected
Sorry, it's me, I had missunderstood, I though that "Default" equal to "Control.DefaultFont"
I have stop tests and try to add new features to Button Sample :
First thing but an issue already exist for this : needed to compile before to use new components added in uixml is very painful.
It seems some things are strange :