Margin of control in window from - winforms

I create a control like this:
public class MyTextBoxControl : System.Windows.Forms.TextBox
{
}
and I drag-drop MyTextBoxControl to a window form, default margin is "3, 3, 3, 3"
My question is "Can I change default margin when drag-drop my control to a form?"
I want set default margin is "5, 5, 5, 5" and when I drag-drop my control to a form, margin is "5, 5, 5, 5". NOT "3, 3, 3, 3"
Thanks.

You'd need to apply the DefaultValueAttribute to the property in your class, but I don't think you can since the property is not virtual.

Related

Binding WPF PopupColorEdit to a Custom List

I'm a WPF's beginner developer, how can I do binding from List or ObserverCollection to PopupColorEdit.
thanks
By looking at the documentation it appears that it has a Palettes property which is a collection of CustomPalette objects. CustomPalettes can be instantiated by giving a name and providing a List of Colors. Like so:
popupColorEdit1.Palettes.Add(
new CustomPalette("Custom RGB Colors", new List<Color>() {
Color.FromRgb(150, 18, 30),
Color.FromRgb(20, 40, 20),
Color.FromRgb(88, 73, 29) }));
So you'd have a collection of CustomPalettes in your viewmodel (or code behind) and bind either from XAML or programatically.
Does that help?

RibbonControl: center Title

I'm using the Microsoft RibbonControl on a UserControl (it needs to be so we can host it on a stub form to host the WPF in our MDI system). Sadly, the title of the Ribbon displays Top/Left in the ribbon's header, and it looks ridiculous. How do I get at that sucker?
I am working on just about the same thing right now. I solved it by using a datatemplate for the ribbon title:
<r:Ribbon.TitleTemplate>
<DataTemplate>
<TextBlock Text="Put you title here" Margin="3,3,0,0"></TextBlock>
</DataTemplate>
</r:Ribbon.TitleTemplate>
If the ribbon is used in a RibbonWindow, you probably also want to add a glow to the title text to be able to read it properly when placed over a dark background. In that case, add this XAML inside the TextBlock:
<TextBlock.BitmapEffect>
<OuterGlowBitmapEffect GlowColor="White" Opacity="0.7" GlowSize="10"/>
</TextBlock.BitmapEffect>
There is one more problem with the Ribbon when used within a RibbonWindow; the title text will either be placed correctly when window state is Normal or when window is maximized. To solve this I bound the TextBlock Margin to a property in the codebind:
public Thickness TitleMargin
{
get { return this.WindowState == WindowState.Maximized ? new Thickness(0, 3, 0, 0) : new Thickness(0); }
}
To get this working, you also need to fire a PropertyChanged event each time the window state changes:
protected override void OnStateChanged(EventArgs e)
{
OnPropertyChanged("TitleMargin");
base.OnStateChanged(e);
}

WPF TabControl with WindowsFormsHost unknown border issue

I am writing a text editor in WPF and I seem to have a strange border that I can't remove.
I've got a grid with a tabcontrol, and when a user selects "File -> New", I programatically add a new tabitem to the tabcontrol. I'm setting the tabitem content to an instance of WindowsFormsHost in order to host the ScintillaNet WinForms control.
Here's the problem: http://i.stack.imgur.com/kotSb.png
I'm pretty sure the border is not coming from the WinForms control itself, as I've used it elsewhere in the same configuration and it has no border.
The red border you see is added by me to highlight the problem (in the method that is responding to File -> New), with the following code:
tabControl.BorderThickness = new Thickness(3, 3, 3, 3);
tabControl.BorderBrush = Brushes.Red;
tabControl.Items.Add(tab);
tab.Focus();
Any ideas where this inner grey border is coming from?
That is the Padding on the TabControl, which is a margin it applies to the hosted child element. See Alignment, Margins, and Padding Overview. It is set to 4 in the default TabControl style. Try setting the Padding to zero explicitly:
tabControl.BorderThickness = new Thickness(3, 3, 3, 3);
tabControl.BorderBrush = Brushes.Red;
tabControl.Padding = new Thickness(0);
tabControl.Items.Add(tab);
tab.Focus();

Move Image on window WPF

Here is my code :
<Image x:Name="Layer_22_copy" Height="542" Canvas.Left="16" Opacity="0.522" Source="gammon2_Images\Layer 22 copy.png" Canvas.Top="13" Width="315"/>
how can i change position of this image on Code Behind?
i am new in WPF.
thank you.
Layer_22_copy.SetValue(Canvas.TopProperty, newTopValue);
Layer_22_copy.SetValue(Canvas.LeftProperty, newLeftValue);
You can set the Margin Property like
Layer_22_copy.Margin = new Thickness(10, 30, 0, 0);

Winforms Checkbox Focus Problem if no Text is Applied on Checkbox

I have a multiple checkboxes on a Winforms without having the Text Property of all checkboxes,
so the problem is that when i hover a mouse on the checkbox it highlighted but when i go to the checkbox using tab key it never get highlighted..
If anyone have the similar issue and already solved it Please help..
The problem is that when a check box gets focus it highlights only the text portion of the control which is empty in your case. You have a few choices:
1) For all your "blank" text boxes, set the text property to a space. This will create a small highlighted portion when you tab to the control.
2) Program the OnEnter and OnLeave events of the checkbox, and draw/paint a square around the whole control.
3) If you want the default MouseEnter behaviour which creates a yellowish highlight on the check box itself, create your own check box control as follows:
public class MyCB : CheckBox
{
protected override void OnEnter(EventArgs e)
{
base.OnEnter(e);
base.OnMouseEnter(e);
}
protected override void OnLeave(EventArgs e)
{
base.OnLeave(e);
base.OnMouseLeave(e);
}
}
I added an event handler for the CheckBox.Paint event and added the following:
private void checkBox1_Paint(object sender, PaintEventArgs e)
{
CheckBox checkBox = sender as CheckBox;
if (checkBox.Focused)
{
// e.ClipRectangle is affected by checkBox.Padding. Be careful when changing the Padding.
ControlPaint.DrawFocusRectangle(e.Graphics, e.ClipRectangle, checkBox.ForeColor, checkBox.BackColor);
}
}
I also adjusted the CheckBox.Padding to be 2, 2, 0, 1 in order to get a border that was 1 pixel from the edge of the CheckBox.
You can fix this by setting the AutoSize property = False. When AutoSize is True, it acts like a Label with AutoSize set to true, in that an empty label will take up almost no space on the screen. With AutoSize = False, you can manually set the bounding rectangle for the checkbox.
If you draw border only, try to set these properties.
AutoSize : False
CheckAlign : MiddleCenter
Font: Courier New, 12.25pt
TextAlign: MiddleRight
Padding : 0, 5, 0, 0
Size : 26, 26
Text : " " (two spaces)

Resources