I have a custom control an inside of it I have a textbox that rotates depending wether you'd like it to collapse or expand, when it is collapsed I want the textbox to be vertical and when it is expanded I want it horizontal.
The problem is that when it is vertical the textbox doesn't show all the text, I've being looking for an answer, and I understand it has to do with the way silverlight updates it's layout. Here is my code
private void CollapseControl()
{
CollapseCommand.Content = "E";
CollapseCommand.Margin = _btnMarginOnCollapse;
BtnZoomIn.Visibility = Visibility.Collapsed;
BtnZoomOut.Visibility = Visibility.Collapsed;
ScrollViewerStackPanel.Visibility = Visibility.Collapsed;
ZoomPanel.Visibility = Visibility.Collapsed;
this.HorizontalAlignment = HorizontalAlignment.Left;
this.Width = 40;
RotateTransform nameRotateTransform = new RotateTransform();
nameRotateTransform.Angle = 270;
Nametb.RenderTransform = nameRotateTransform;
Nametb.VerticalAlignment = VerticalAlignment.Bottom;
Nametb.Height = Nametb.Width;
Nametb.Width = Nametb.Height;
Nametb.UpdateLayout();
}
One solution would be to use the LayoutTransformer control from the Silverlight toolkit.
You wrap the existing textblock inside a LayoutTransformer
<toolkit:LayoutTransformer x:Name="Namelt" ...>
<toolkit:LayoutTransformer.LayoutTransform>
<RotateTransform />
</toolkit:LayoutTransformer.LayoutTransform>
<TextBlock x:Name="Nametb" Text="Hello World" />
</toolkit:LayoutTransformer>
Then your code looks like:-
((RotateTransform)Namelt.LayoutTransform).Angle = 270;
Namelt.VerticalAlignment = VerticalAlignment.Bottom;
Namelt.Height = Nametb.Width;
Namelt.Width = Nametb.Height;
I just recently ran into a similar problem, and came up with the following solution (based on a post on the Silverlight forums), which should help with your issue, too:
private void CollapseControl()
{
CollapseCommand.Content = "E";
CollapseCommand.Margin = _btnMarginOnCollapse;
BtnZoomIn.Visibility = Visibility.Collapsed;
BtnZoomOut.Visibility = Visibility.Collapsed;
ScrollViewerStackPanel.Visibility = Visibility.Collapsed;
ZoomPanel.Visibility = Visibility.Collapsed;
this.HorizontalAlignment = HorizontalAlignment.Left;
LayoutTransform lt = new LayoutTransform();
lt.Content = Nametb;
RotateTransform nameRotateTransform = new RotateTransform();
nameRotateTransform.Angle = 270;
lt.LayoutTransform = nameRotateTransform;
lt.ApplyLayoutTransform();
Nametb.UpdateLayout();
}
I just written following and my similar problem is solved.
layoutTransform.VerticalAlignment = VerticalAlignment.Bottom;
layoutTransform.VerticalAlignment = VerticalAlignment.Center;
Related
I am currently working on a devexpress project and I am using the checkbutton tool. I have it doing everything I want except for a very annoying sick looking blueline that shows up on appearance.hover and appearance.pressed.
If anything at all I would expect a color that goes with the theme but a constant blueline no matter what skin is selected is annoying and feels like an old html design.
I have tried setting the bordercolor and all but still.
Below is my code of what I have tried by far from form.Designer.cs;
this.cBtnFilter.AllowFocus = false;
this.cBtnFilter.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cBtnFilter.AppearanceDisabled.Options.UseBackColor = true;
this.cBtnFilter.AppearanceHovered.BorderColor = System.Drawing.Color.White;
this.cBtnFilter.AppearanceHovered.Options.UseBackColor = true;
this.cBtnFilter.AppearanceHovered.Options.UseBorderColor = true;
this.cBtnFilter.AppearancePressed.BorderColor = System.Drawing.Color.White;
this.cBtnFilter.AppearancePressed.Options.UseBackColor = true;
this.cBtnFilter.AppearancePressed.Options.UseBorderColor = true;
this.cBtnFilter.ImageOptions.AllowGlyphSkinning = DevExpress.Utils.DefaultBoolean.False;
this.cBtnFilter.ImageOptions.Location = DevExpress.XtraEditors.ImageLocation.MiddleCenter;
this.cBtnFilter.ImageOptions.SvgImage = global::form.Properties.Resources.icon_filter;
this.cBtnFilter.ImageOptions.SvgImageSize = new System.Drawing.Size(40, 40);
this.cBtnFilter.Location = new System.Drawing.Point(355, 40);
this.cBtnFilter.LookAndFeel.SkinName = "The Bezier";
this.cBtnFilter.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.UltraFlat;
this.cBtnFilter.LookAndFeel.UseDefaultLookAndFeel = false;
this.cBtnFilter.Name = "cBtnFilter";
this.cBtnFilter.PaintStyle = DevExpress.XtraEditors.Controls.PaintStyles.Light;
this.cBtnFilter.ShowFocusRectangle = DevExpress.Utils.DefaultBoolean.False;
this.cBtnFilter.Size = new System.Drawing.Size(50, 50);
toolTipTitleItem4.Text = "Show active Only";
superToolTip4.Items.Add(toolTipTitleItem4);
this.cBtnFilter.SuperTip = superToolTip4;
this.cBtnFilter.TabIndex = 39;
this.cBtnFilter.Click += new System.EventHandler(this.Filter_Click);
The attached image is an example of when it is selected and when it is hovered respectively.
At the least if I could completely remove the blue line or change it to the theme color. It would be great.
Am using Devexpress Version 20.2.4
how I solved this is by using the simple button instead and making it act like a toggle button.
this method handles the toggle for me
public Boolean buttonState = false;
private void ToggleButton()
{
if (buttonState)
{
simpleButton.Appearance.BackColor = Color.Red;
buttonState = false;
}
else
{
simpleButton.Appearance.BackColor = Color.White;
buttonState = true;
}
}
this is the button
private void simpleButton_Click(object sender, EventArgs e)
{
ToggleButton();
}
here is the button in Designer.cs
this.simpleButton1.AllowFocus = false;
this.simpleButton1.AppearanceHovered.BackColor = System.Drawing.Color.Teal;
this.simpleButton1.AppearanceHovered.Options.UseBackColor = true;
this.simpleButton1.Location = new System.Drawing.Point(524, 214);
this.simpleButton1.LookAndFeel.SkinName = "The Bezier";
this.simpleButton1.LookAndFeel.UseDefaultLookAndFeel = false;
this.simpleButton1.Name = "simpleButton1";
this.simpleButton1.ShowFocusRectangle = DevExpress.Utils.DefaultBoolean.False;
this.simpleButton1.Size = new System.Drawing.Size(157, 150);
this.simpleButton1.TabIndex = 2;
this.simpleButton1.Text = "simpleButton";
this.simpleButton1.Click += new System.EventHandler(this.simpleButton1_Click);
Its quite straightforward. In case anyone has a better way or has need for this, knock yourself(ves) out.
Hopefully in the future, Devexpress will not force blue borders on us.
I'm writing a program that starts out with requiring a certain amount of lines of text and for that I use a TextBox. To make the program look nice, I put a background image on the form. Now I don't want the TextBox to put a large white block on the image, so for that I made the TextBox have a transparent background. But here's the problem: as soon as I start putting text in the TextBox, the lines that have text will revert back to the white background that I don't want. So how can I stop my program from doing that?
I can't post images yet, so I'll just use links:
This image shows the background as I have it and how I want it to be:
This image shows what happens when I start typing:
I want the background to just remain the same while I type (of course the text colour should then be lighter, but the textbox.forecolor seems to have no effect.
So below is the code I have so far, I hope you can help me, I'm still quite new to this :)
public class NieuwSpel : Form
{
Label spelerslijst, nummer;
TextBox spelersInput, spelnr;
Button OK;
public NieuwSpel()
{
this.BackgroundImage = WeerwolvenvanWakkerdam.Properties.Resources.Background_NieuwSpel;
this.FormBorderStyle = FormBorderStyle.Fixed3D;
spelerslijst = new Label();
spelerslijst.Location = new Point(10, 10);
spelerslijst.Text = "Voer hier de spelerslijst in:";
spelerslijst.Width = 200;
spelerslijst.BackColor = Color.Transparent;
spelerslijst.ForeColor = Color.White;
this.Controls.Add(spelerslijst);
spelersInput = new CustomTextBox();
spelersInput.Location = new Point(10, 40);
spelersInput.Size = new Size(200, 300);
spelersInput.Multiline = true;
spelersInput.BackColor = Color.FromArgb(100, 100, 100, 100);
spelersInput.ForeColor = Color.White;
spelersInput.GotFocus += this.setColour;
this.Controls.Add(spelersInput);
OK = new Button();
OK.Text = "Start Spel!";
OK.Location = new Point(110, 430);
OK.Click += this.Start;
this.Controls.Add(OK);
nummer = new Label();
nummer.Text = "Spelnummer:";
nummer.Width = 75;
nummer.Location = new Point(10, 360);
nummer.BackColor = Color.Transparent;
nummer.ForeColor = Color.White;
this.Controls.Add(nummer);
spelnr = new CustomTextBox();
spelnr.Width = 50;
spelnr.Height = 20;
spelnr.Location = new Point(90, 360);
spelnr.BackColor = Color.FromArgb(100, 100, 100, 100);
spelnr.ForeColor = Color.White;
this.Controls.Add(spelnr);
}
public void setColour(object o, EventArgs ea)
{
((CustomTextBox)o).BackColor = Color.FromArgb(100, 100, 100, 100);
}
}
public partial class CustomTextBox : TextBox
{
public CustomTextBox()
{
SetStyle(ControlStyles.SupportsTransparentBackColor |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw |
ControlStyles.UserPaint, true);
}
}
This probably won't be easy in WinForms. If you're just messing around on your own and trying to learn, you might want to consider playing around with WPF. A lot of people still have to deal with WinForms, but I've developed in both and WPF definitely supersedes it.
It can provide the desired effect out-of-the-box:
<Window x:Class="SampleWpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:SampleWpf"
Title="MainWindow" Height="250" Width="400" >
<Window.Background>
<ImageBrush ImageSource="images.jpg" />
</Window.Background>
<Grid>
<TextBox Margin="5" Background="Transparent" Text="HELLO THERE!"
FontSize="20" FontWeight="Bold" Foreground="White" />
</Grid>
</Window>
I have trying to use that about bopx in my WPF application http://www.nuget.org/packages/AboutBox/
but i cant figure out how to resize it and how to make it not dragable. I tried that but no way:
About about = new About();
about.Window.Width = 120;
about.Window.Height = 130;
about.Window.MaxWidth = 120;
about.Window.MaxHeight = 130;
about.Window.MinWidth = 120;
about.Window.MinHeight = 130;
about.Window.ResizeMode = ResizeMode.NoResize;
about.Window.WindowStyle = WindowStyle.ToolWindow;
about.Window.WindowState = WindowState.Minimized;
about.Window.AllowDrop = false;
about.Show();
May be some one may help.
Also I would like to display close or OK button to close the window, and want to disable closing window when focus is loosing.
UPDATE:
I ended up by using http://wpfmbx.codeplex.com/ it is exactly what i need
I have not tried that About box but following should be the correct order for heights:
About about = new About();
about.Window.MinWidth = 120;
about.Window.MinHeight = 130;
about.Window.MaxWidth = 120;
about.Window.MaxHeight = 130;
about.Window.Width = 120;
about.Window.Height = 130;
MinWidth/MinHeight takes precedence then comes MaxWidth/MaxHeight and Width/Height. I am not 100 % sure that it is the cause of your problem, just give it a try.
To be able to make it drag-able manually, then you just need to call DragMove(), on MouseDown or some similar event.
how can I set the style in app.xaml to my button in c# ?
there is a style for buttons in app.xaml and I want to use it in my button in c#.
here is my code for the button.
Button deleteButton = new Button();
deleteButton.Background = new ImageBrush
{
ImageSource ="Delete2.png"
};
deleteButton.Height = 70;
deleteButton.Width = 70;
deleteButton.HorizontalAlignment = HorizontalAlignment.Left;
deleteButton.VerticalAlignment = VerticalAlignment.Bottom;
deleteButton.Margin = new Thickness(0,10,0,-5);
deleteButton.BorderBrush = null;
deleteButton.Visibility = Visibility.Collapsed;
deleteButton.Click += new RoutedEventHandler(ItemDeleteButton_Click);
deleteButton.Tag = tag;
deleteButton.Style = ?????????????????
Try this code
deleteButton.Style = App.Current.Resources["StyleKey"] as Style;
You can use FindResource or TryFindResource.
Resources and Code - MSDN
I solved it
deleteButton.Style = App.Current.Resources["ButtonStyle"] as Style;
Your Style is probably defined in a ResourceDictionary elsewhere in your application. You can retrieve that using the FindResource method:
deleteButton.Style = (Style)this.FindResource("MyCustomButtonStyle");
There is a lot of already answered question and examples about how to draw images within combobox. But I haven't found any examples how to draw animations within combobox.
The gif animation I use is (it's transparent):
And the result I want to achieve is somethink like this:
I'm using Windows Forms and .Net 3.5.
All ways of achieving that, I thought about, were:
1. Use Graphics.DrawImage in ComboBox's DrawItem handler. But the image was drawn statically, there was no anmation.
2. Use PictureBox to show animation and then somehow resize it and place over the ComboBox.
For second soultion I used the following code:
pictureBox1 = new PictureBox();
pictureBox1.Image = Resource.myImage;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
//3 is used just for try to fit image into "white" area of ComboBox
pictureBox1.ClientSize = new Size(comboBox1.Size.Height-3, comboBox1.Size.Height-3);
pictureBox1.BackColor = System.Drawing.Color.Transparent;
pictureBox1.Dock = DockStyle.Left;
pictureBox1.Parent = this.comboBox1;
pictureBox1.Enabled = true;
pictureBox1.Visible = true;
But in result I've got this:
It's animated, but picturebox is drawn on ComboBox edges and it looks bad.
So, can anyone give me an advice or some help to achive this?
Thank you.
EDIT:
My final solution that worked:
pictureBox1 = new PictureBox();
pictureBox1.Image = Resource1.myImage;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.ClientSize = new Size(comboBox1.Size.Height - SystemInformation.Border3DSize.Height, comboBox1.Size.Height - (2 * SystemInformation.Border3DSize.Height));
pictureBox1.BackColor = System.Drawing.Color.Transparent;
pictureBox1.Location = new Point(SystemInformation.Border3DSize.Width, SystemInformation.Border3DSize.Height);
pictureBox1.Parent = this.comboBox1;
pictureBox1.Enabled = true;
pictureBox1.Visible = true;
Thank you all! You help me a lot!
Try this:
pictureBox1 = new PictureBox();
pictureBox1.Image = Resource.myImage;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
//2 is used just for try to fit image into "white" area of ComboBox
pictureBox1.ClientSize = new Size(comboBox1.Size.Height - 2, comboBox1.Size.Height - 2);
pictureBox1.BackColor = System.Drawing.Color.Transparent;
pictureBox1.Left = 1;
pictureBox1.Top = 1;
pictureBox1.Parent = this.comboBox1;
pictureBox1.Enabled = true;
pictureBox1.Visible = true;
remove the code that sets the "Dock" property. Setting this causes the layout manager to ignore size/location settings.
Instead, set the Size property and the Location property to specific values.
Something like:
pictureBox3.Size = new Size(comboBox1.Size.Height-3, comboBox1.Size.Height-3);
pictureBox3.Location = new Point(0, 3);
You may have to adjust these to get the extact position you need.
It might be then a tad too small, but it would fit, if you set the size of your combobox to pictureBox1.Size = new Size(comboBox1.ItemHeight, comboBox1.ItemHeight).
Or set the height and width to 2*SystemInformation.3DBorderSize