Custom shaped form control

change windows form style c#
how to use css in windows form application c#
windows forms style sheet
how to use stylesheet in windows application c#
css in winforms

I have very very little knowledge in C# and I am trying to make a WinForms application to create 8x8 pixels monochrome bitmaps. I want the user interface look like below:

Here, each of the black bordered boxes will represent a pixel, and simply when user click one of them, it will be filled with black so a "pixel would be set".

I looked for a way of converting standard button control to a custom shape, but could not find an elegant way. I don't want to create these black boxes programmatically, if possible. How can I create such black boxes that will act like a toggle button?

Note: I created the sample picture using graphical design tool and Visual Studio, it is not from a real application. It is the target I want to achieve. There will be other form elements to control the created bitmap in the final application.

You are looking to use a CheckBox control. You want the following properties (don't worry it can be set in the property grid it's only to show the actual property and values) :

CheckBox myCheckBox = new CheckBox();

// change the look to a button style
myCheckBox.Appearance = System.Windows.Forms.Appearance.Button;

// put white background to match your design
myCheckBox.BackColor = System.Drawing.Color.White;

// make button style flat to get rid of the 3d-esque look
myCheckBox.FlatStyle = System.Windows.Forms.FlatStyle.Flat;

// either center image or scale should look good
myCheckBox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;

// set to your empty picture by default and on the checked changed you will swap that
myCheckBox.BackgroundImage = /* whaever image is default */;

then on the checked changed event just change the background image. The check box as it does allow 2 states you will be able to nicely use the Checked property to know the status which is easier to handle that having a button and storing a value for each.

Custom shaped form control, C# Shapped Form control move create custom shape to form in Windows Forms C# applications. The shaped form control provides an additional property, Shape, to add the shapes predefined or create a new custom shape as demand. It offers the ThemeName property to configure the name of the themes in Shaped Form control. The simple C# code snippet below shows how to change the theme name. this.ThemeName = "Office2007Blue";

This could be done with a standard button. You would need to set the button's FlatStyle property to Flat, and empty the Text property, and add a Click event. Each button's click event can then be mapped to the following method:

private void Pixel_Click(object sender, EventArgs e)
  ((Button)sender).BackColor = ((Button)sender).BackColor == Color.Black
    ? Color.White
    : Color.Black;

The button can easily be resized in the IDE to make it square. You would also set the initial colour to either white or black in the IDE.

Shaped Form WinForm Controls, Shaped Form C# Component for , From the Toolbox, drag a Button control to the form as shown in Fig 2. In the Properties window, set the Text property to " X ". Double-click the Button to add a � Custom Shaped Forms/Controls. I would like to create a custom shaped form and I beleive the graphics path is what I am looking for but cannot find any info.

First I created 1 button. In the properties of the button set the following:

FlatStyle = Flat  
FlatAppearance => BorderColor = Black  
FlatAppearance => BorderSize = 4

Then copy and create 63 more button and arrange like your picture.

For each button create a click event and you do like the following code so that when clicked it will make the background color to black. If the background was already Black it will set it back to white.

private void button1_Click(object sender, EventArgs e)
    if (button1.BackColor == Color.Black)
        button1.BackColor = Color.White;
        button1.BackColor = Color.Black;

Creating Custom Shaped Windows Forms in .NET, The ShapedForm control allows you to design and display a Windows form with preset shapes or allow you to create a new custom shape in the Shape Editor. The Shaped Form control descends from the standard Window Forms and is easy to customize the shape of both Windows Forms and controls. With this feature, developers can move, close, minimize and maximize the form with the title bar.

Customizing ShapedForm | UI for WinForms Documentation, Shaped .NET Windows Forms. Every Windows Form has a member object called Region, but by default, Windows Forms do not have custom regions assigned. It makes positioning controls on a shaped form a bit tricky, but beyond that� So you'll have to create custom-shaped forms the other way—by setting a custom region. Basically, you create a Region object (which is basically just a polygon) to describe the desired shape of your form, and then assign that to the form's Region property.

Shaped .NET Windows Forms, This is a brief and easy way to get basic custom shapes for your Windows WinForms in . How Duration: 9:01 Posted: Jul 4, 2014 Because the <mat-form-field> uses the OnPush change detection strategy, we need to let it know when something happens in the form field control that may require the form field to run change detection.

How to Create Custom Shape Forms, The UserControl object has a rectangular shape by default. However, a custom control need not be rectangular. It's possible to create irregularly shaped forms,� To determine the type of control (Form or ActiveX), select and right-click the control, and then display the shortcut menu: If the shortcut menu contains the command Properties, the control is an ActiveX control, and you are in design mode. If the shortcut menu contains the command Assign Macro, the control is a Form control.

  • Let's ignore those gray dots between the square..
  • That looks like a simple class that defines a Rectangle. A bool Selected, Color BorderColor and Color FillColor properties with a manager class that handles the List<RectangleClass>, defines the size of the gaps and toggles the Selected value when Rectangle.Contains(Point) on a Mouse.Click event. The Paint/OnPaint event of the container can pass the e.Graphics object to the manager class that paints all the Rectangles in their current state.
  • And once you have the custom calss or an image checkbox you can programatically put them in a 2d array so you can easly get x,y coordinate
  • This is the exact answer I was looking for. Looks like very simple point but since I am noob on C#, it was hard for me to find. Thanks!
  • you should change all isntances of Pixel. to ((Button)sender). the sender will be the button itself and if he create many buttons he could then map this event to all the buttons instead of writing one for each.
  • @Franck Thanks, I've updated the answer to include that.