using inputbox;
using Microsoft.VisualBasic;
{
string msg, title, df;
object myvalue;
msg = "input";
title = "test";
df = "bb";
myvalue = Interaction.InputBox(msg, title, df);
if ((string)myvalue=="")
{
myvalue = df;
Interaction.MsgBox("MyValue=" + myvalue.ToString(), MsgBoxStyle.OkOnly | MsgBoxStyle.Information, "C# Msgbox Demo");
}
else {
Interaction.MsgBox("Hello, " + myvalue.ToString() + "!"+Environment.NewLine+"Nice to meet you",MsgBoxStyle.OkOnly|MsgBoxStyle.Information,"C# Demo");
}
}
https://www.youtube.com/watch?v=LEsl_psykrQ&t=4s
วันพฤหัสบดีที่ 30 เมษายน พ.ศ. 2563
วันพุธที่ 29 เมษายน พ.ศ. 2563
ส่งค่าข้าม Form
ฟอร้มหลัก
if (Application.OpenForms["formnutri05"] != null)
{
Application.OpenForms["formnutri05"].Close();
}
formnutri05 frm = new formnutri05();
frm.ConJ = connectionJhcis;
frm.ConServer = connectionServer;
frm.hcode = hcode;
frm.hname = hname;
frm.yearprocess = yearprocess;
frm.MdiParent = this;
frm.Dock = DockStyle.Fill;
frm.Show();
// ต้องเรียงลำดับตามนี้ ก่อนฟอร์ม โชว์
ฟอร์มที่รับค่า
public string hcode { get; set; }
public string hname { get; set; }
public int yearprocess { get; set; }
public MySqlConnection ConJ { get; set; }
public MySqlConnection ConServer { get; set; }
if (Application.OpenForms["formnutri05"] != null)
{
Application.OpenForms["formnutri05"].Close();
}
formnutri05 frm = new formnutri05();
frm.ConJ = connectionJhcis;
frm.ConServer = connectionServer;
frm.hcode = hcode;
frm.hname = hname;
frm.yearprocess = yearprocess;
frm.MdiParent = this;
frm.Dock = DockStyle.Fill;
frm.Show();
// ต้องเรียงลำดับตามนี้ ก่อนฟอร์ม โชว์
ฟอร์มที่รับค่า
public string hcode { get; set; }
public string hname { get; set; }
public int yearprocess { get; set; }
public MySqlConnection ConJ { get; set; }
public MySqlConnection ConServer { get; set; }
ตรวจสอบเปิด form ซ้ำ
if (Application.OpenForms["formnutri05"] != null)
{
Application.OpenForms["formnutri05"].Close();
}
formnutri05 frm = new formnutri05();
frm.MdiParent = this;
frm.Dock = DockStyle.Fill;
frm.Show();
frm.ConJ = connectionJhcis;
frm.ConServer = connectionServer;
frm.hcode = hcode;
frm.hname = hname;
frm.yearprocess = yearprocess;
{
Application.OpenForms["formnutri05"].Close();
}
formnutri05 frm = new formnutri05();
frm.MdiParent = this;
frm.Dock = DockStyle.Fill;
frm.Show();
frm.ConJ = connectionJhcis;
frm.ConServer = connectionServer;
frm.hcode = hcode;
frm.hname = hname;
frm.yearprocess = yearprocess;
วันอังคารที่ 28 เมษายน พ.ศ. 2563
เพิ่มปีใน Combobox +- 10 ปี
1.สร้าง class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace testmenu
{
public class yearP
{
public string tyear { get; set; }
public int pyear { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace testmenu
{
public class yearP
{
public string tyear { get; set; }
public int pyear { get; set; }
}
}
2.สร้าง procedure ใน Form
void AddValue()
{
comboBox1.Items.Clear();
int year = DateTime.Now.Year;
string a = year.ToString();
//comboBox1.Items.Add(a);
List<yearP> list = new List<yearP>();
for (int i = 1; i <= 10; i++)
{
int my = year + i;
string tmy = (my + 543).ToString();
list.Add(new yearP() { tyear = tmy, pyear = my });
}
for (int i = 0; i <= 10; i++)
{
int my = year - i;
string tmy = (my + 543).ToString();
list.Add(new yearP() { tyear = tmy, pyear = my });
}
comboBox1.DataSource = list;
comboBox1.ValueMember = "pyear";
comboBox1.DisplayMember = "tyear";
}
3.เรียกใช้
private void FormMain_Load(object sender, EventArgs e)
{
AddValue();
comboBox1.SelectedIndex = 10;
}
How to: Make the entire focused row highlighted เลือกทั้งแถว
This example shows how to paint the focused cell using the same appearance as the entire focused row:
// Make the grid read-only. gridView1.OptionsBehavior.Editable = false; // Prevent the focused cell from being highlighted. gridView1.OptionsSelection.EnableAppearanceFocusedCell = false; // Draw a dotted focus rectangle around the entire row. gridView1.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
วันอาทิตย์ที่ 26 เมษายน พ.ศ. 2563
C# - Logical Operators
| Operator | Description | Example |
|---|---|---|
| && | Called Logical AND operator. If both the operands are non zero then condition becomes true. | (A && B) is false. |
| || | Called Logical OR Operator. If any of the two operands is non zero then condition becomes true. | (A || B) is true. |
| ! | Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. | !(A && B) is true. |
Example
using System; namespace OperatorsAppl { class Program { static void Main(string[] args) { bool a = true; bool b = true; if (a && b) { Console.WriteLine("Line 1 - Condition is true"); } if (a || b) { Console.WriteLine("Line 2 - Condition is true"); } /* lets change the value of a and b */ a = false; b = true; if (a && b) { Console.WriteLine("Line 3 - Condition is true"); } else { Console.WriteLine("Line 3 - Condition is not true"); } if (!(a && b)) { Console.WriteLine("Line 4 - Condition is true"); } Console.ReadLine(); } } }
วันเสาร์ที่ 25 เมษายน พ.ศ. 2563
Get connection string from App.config
using System.Configuration;
//--------------------------------------------
InitializeComponent();
var j = Properties.Settings.Default;
string jserver = j.jserver;
string jport = j.jport.ToString();
string jdbname = j.jdbname;
string jusername = j.juser;
string jpassword = j.jpassword;
StringBuilder jsb = new StringBuilder();
jsb.Append("server=" + jserver + ";");
jsb.Append("port=" + jport + ";");
jsb.Append("Database=" + jdbname + ";");
jsb.Append("Uid=" + jusername + ";");
jsb.Append("Pwd=" + jpassword + ";");
jsb.Append("CharSet=utf8;");
jsb.Append("Convert Zero Datetime=True;Use Affected Rows=true;AllowUserVariables=True;CheckParameters=False;");
string jconString = jsb.ToString();
jcon = new MySqlConnection(jconString);
//--------------------------------------------
InitializeComponent();
var j = Properties.Settings.Default;
string jserver = j.jserver;
string jport = j.jport.ToString();
string jdbname = j.jdbname;
string jusername = j.juser;
string jpassword = j.jpassword;
StringBuilder jsb = new StringBuilder();
jsb.Append("server=" + jserver + ";");
jsb.Append("port=" + jport + ";");
jsb.Append("Database=" + jdbname + ";");
jsb.Append("Uid=" + jusername + ";");
jsb.Append("Pwd=" + jpassword + ";");
jsb.Append("CharSet=utf8;");
jsb.Append("Convert Zero Datetime=True;Use Affected Rows=true;AllowUserVariables=True;CheckParameters=False;");
string jconString = jsb.ToString();
jcon = new MySqlConnection(jconString);
สมัครสมาชิก:
บทความ (Atom)
