1024programmer Asp.Net drawing in winform

drawing in winform

Drawing in winform

This article introduces the implementation process of drawing using chartcontrol in winform.

Today I would like to share with you the implementation of the drawing function in a program I recently made.

Let’s take a look at the effect first:

Drawing Effect

Concrete implementation

Page design

The design of the drawing settings page is as follows:

image-20231130103107766

4 label controls, the controls are as follows:

image-20231130103225679

2 DateEdit controls, the controls are as follows:

image-20231130103311866

1 ComboBoxEdit control, the control is as follows:

image-20231130103435053

1 CheckedListBoxControl control, the control is as follows:

image-20231130103557605

1 SimpleButton control, the control is as follows:

image-20231130103726179

The page design for drawing display is as follows:

image-20231130104234323

There is only one ChartControl control, and the control is as follows:

image-20231130104310698

code

The data drawn is the data obtained by using C# to implement a crawler to obtain web page data mentioned in the previous article, as shown below:

image-20231130141548429

Only the minimum temperature, maximum temperature, minimum visibility, and maximum visibility are used for plotting in these data.

The first step is to obtain the contents of ComboBoxEdit and CheckedListBoxControl when loading the form:

 public void init  ()
{
// Assign a value to the drop-down box
var comboBoxItems = db.Queryable<WeatherData>().Select(x => x.StationName).Distinct ().ToList();
comboBoxEdit1.Properties.Items.AddRange(comboBoxItems);
comboBoxEdit2.Properties.Items.AddRange(comboBoxItems) ;

// Multi-select box settings
checkedListBoxControl1.CheckOnClick = true; // Set to Click to select or uncheck

// The value in the multi-select box
string[] indexs = { "Minimum temperature (℃ )", "Maximum temperature (℃)", "Minimum visibility (km)", " Maximum visibility (km)" };
// Add items to the multi-select box
var checkedItems = new List<CheckedListBoxItem>();
foreach (var index in indexs)
{
var checkedItem = new CheckedListBoxItem();
checkedItem.Value = index;
checkedItems.Add(checkedItem);
}
checkedListBoxControl1.Items.AddRange(checkedItems.ToArray());

}
private void ToolbarForm1_Load(object sender, EventArgs e)
{
init();
}

Get different site names:

 var comboBoxItems = db.Queryable<WeatherData>()
                           . cm-operator">=> x.StationName).Distinct().ToList();

Add a value to the drop-down box:

 comboBoxEdit1.Properties.Items.AddRange(comboBoxItems);

Add a value to the checkbox:

 // Multi-select box settings
checkedListBoxControl1.CheckOnClick = true; // Set to select or uncheck with one click

// The value in the multi-select box
string[] indexes = { "Minimum temperature (℃)", "Maximum temperature (℃)", "Minimum visibility (km)", "Highest visibility (km)" };
// Add items to the multi-select box
var checkedItems = new List<CheckedListBoxItem>();
foreach (var index in indexs)
{
var checkedItem = new CheckedListBoxItem();
checkedItem.Value = index;
checkedItems.Add (checkedItem);
}
checkedListBoxControl1.Items .AddRange(checkedItems.ToArray());

Click event code of the start drawing button:

 private void simpleButton3_Click(object sender, EventArgs e)
{
var date1 = dateEdit3.EditValue;
var date2 = dateEdit4.EditValue;
var name = comboBoxEdit2. Text;
var checkedItems = checkedListBoxControl1.CheckedItems;
if (date1 != null && date2 ! = null && name != "" && checkedItems.Count != 0)
{
&nable">Date, dataPoint.Visibility_Low));

                  }<br series3);
                                                                                  Visibility (km)":
                                                                           cm-keyword">new Series("Highest visibility (km)", ViewType.Line);
foreach (var dataPoint in list)
                                                                                        span class="cm-variable">Points.Add(new SeriesPoint(dataPoint.Date, dataPoint.Visibility_High));

                                                                 variable">Add(series4);
                                                                                                                                                        >

Drawing code:

Series series1 = new Series("Minimum temperature (℃)", ViewType.Line);
                                                                                            >var dataPoint in list)
                                                                    span class="cm-variable">series1.Points.Add(new SeriesPoint(dataPoint.Date, dataPoint.Tem_Low));

                                                                                                             variable">Series.Add(series1);

The final drawing effect is as follows:

image-20231130145230125

The above is the implementation process of drawing in winform in this case. I hope it will be helpful to you.

The final drawing effect is as follows:

image-20231130145230125

The above is the implementation process of drawing in winform in this case. I hope it will be helpful to you.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/811163

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索