C# 取得傳來的byte資料
從第3個BYTE開始
string[] 資料 = System.Text.Encoding.Unicode.GetString(位元陣列, 3, 位元陣列.Length - 3).Split('\t');
byte[] s =Guid.NewGuid().ToByteArray();
string c = System.Text.Encoding.Unicode.GetString(s);
byte[] d = System.Text.Encoding.Unicode.GetBytes(c);
for (int i = 0; i < s.Length; i++)
{
if (s[i] == d[i])
{
int k = 0;
}
}
createps 發表在 痞客邦 留言(0) 人氣(406)
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.FormClosed += new FormClosedEventHandler(frm2_FormClosed);
frm2.Show();//開啟子視窗
this.Hide();//隱藏父視窗
}
void frm2_FormClosed(object sender, FormClosedEventArgs e)
{
this.Show();//子視窗關閉時,父視窗再顯示出來
}
createps 發表在 痞客邦 留言(0) 人氣(1,770)
跨執行緒呼叫控制項
在非同步概觀這篇文章提到如果在別的執行緒中直接操作Windows Form上的任何一個控制項,換句話說就是操作控制項的執行緒與建立控制項的執行緒並不是同一個,就會產生InvalidOperationException。這是.Net Framework中針對多執行緒工作所設下的一道安全性機制。
執行緒使用委派
private delegate void 委派_函式(string data);
private void 函式(string data)
{
if (this.InvokeRequired)
{
委派_函式 a = new 委派_函式(函式);
this.Invoke(a,data);
}
else
{
this.textbox.Text = data;
}
}
createps 發表在 痞客邦 留言(0) 人氣(2,175)
DateTime.Now.ToString("HH:mm:ss MM月dd日yyyy年");
HH:24小時制
hh:12小時制
MM:月份
mm:分鐘
createps 發表在 痞客邦 留言(0) 人氣(489)
this.listView1 = new System.Windows.Forms.ListView();
//
// listView1
//
this.listView1.Location = new System.Drawing.Point(26, 119);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(304, 97);
this.listView1.TabIndex = 6;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;//這個是重點,有這個才會顯示Columns的
createps 發表在 痞客邦 留言(0) 人氣(5,849)
C# 開啟執行檔
開啟執行檔
System.Diagnostics.Process.Start("notepad.exe"); // 記事本
System.Diagnostics.Process.Start("calc.exe"); // 小算盤
後面加參數
System.Diagnostics.Process.Start("自己寫的執行檔.exe","自己需要的參數");
再配合主程式
static void Main(string[] 自己需要的參數)
{
if (自己需要的參數[0] != "asldfie09484")
return;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
createps 發表在 痞客邦 留言(0) 人氣(2,212)
class Calendar1
{
public const int months = 12;
}
class Calendar2
{
const int months = 12, weeks = 52, days = 365;
}
class Calendar3
{
const int months = 12;
const int weeks = 52;
const int days = 365;
const double daysPerWeek = days / weeks;
const double daysPerMonth = days / months;
}
常數可以標記為 public、private、protected、internal 或 protectedinternal。這些存取修飾詞將定義類別使用者如何存取常數。如需詳細資訊,請參閱存取修飾詞 (C# 程式設計手冊)。
常數會當做靜態欄位存取,但不能使用 static 關鍵字。若運算式不在定義常數的類別中,就必須使用類別名稱、句號和常數名稱來存取常數。例如:
createps 發表在 痞客邦 留言(0) 人氣(118)
try
{
string s = null;
ProcessString(s);
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
createps 發表在 痞客邦 留言(0) 人氣(68)
System.Diagnostics.Debugger.Break();
相對vb的 Stop
createps 發表在 痞客邦 留言(0) 人氣(193)
用1-52數字表示撲克牌的每一張牌
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim a() As Integer = {1, 6, 9, 15, 14, 19, 52, 18, 33, 11, 18}
For i As Integer = 0 To a.Length - 1
Me.count(a(i))
Next
End Sub
Private card(13) As Integer
Private Sub count(ByVal number As Integer)
Dim i As Integer = (number - 1) \ 4 + 1
Me.card(i) += 1
End Sub
重點如下
在VB中運算符''/''和''\''都是除法運算符。
當被除數和除數有一個是浮點數時二者沒有什麼差別。
當二者都為整型時,''\''是商取整,''/''是商有小數也有整數。
createps 發表在 痞客邦 留言(0) 人氣(252)