更新中...
- 窗體不能被拉伸 FormBorderStyle 屬性設置為FixedToolWindow
- 默認居中顯示 StartPosition : CenterScreen
//textbox 提示文字 (來源:百度知道)
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Baidu_20131113_1
{
public partial class Form1 : Form
{
/// <summary>
/// 文本框中的提示信息
/// </summary>
private const string Hint = "input something here...";
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 用于處理文本框的單擊事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBoxMessage_Click(object sender, EventArgs e)
{
// 如果文本框的文本值不等于提示信息,直接返回
if (!this.textBoxMessage.Text.Trim().Equals(Hint))
{
return;
}
// 否則
// 將文本框的字體顏色設為黑色
this.textBoxMessage.ForeColor = Color.Black;
// 將文本框清空
this.textBoxMessage.Clear();
}
/// <summary>
/// 用于處理文本框的鼠標離開事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBoxMessage_MouseLeave(object sender, EventArgs e)
{
// 如果文本框的文本值不為空,直接返回
if (!string.IsNullOrEmpty(this.textBoxMessage.Text.Trim()))
{
return;
}
// 否則
// 將文本框的字體顏色設為銀色
this.textBoxMessage.ForeColor = Color.Silver;
// 將文本框的文本值設為提示信息
this.textBoxMessage.Text = Hint;
}
}
}
參考資料
網絡請求
網絡請求
listview分頁
listview分頁
winform控件自定義等
CYQ 連接access數據庫 以及讀取數據遍歷
/// MAction("表名","連接字符串")
using (MAction action = new MAction("test", string.Format("Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0}", AppDomain.CurrentDomain.BaseDirectory + "Database1.accdb"))) {
MDataTable table = action.Select();
//string str = table.Rows[0]["姓名"].Value.ToString();
for (int i = 0; i < table.Rows.Count; i++)
{
foreach (MDataCell mdc in table.Rows[i]) {
string strValue = mdc.Value.ToString();
string strName = mdc.ColumnName.ToString();
System.Diagnostics.Debug.WriteLine(" ddd "+strName+" --- " + strValue);
}
}
}
CYQ連接文本數據庫 讀取數據
//void LoadData()
//{
// int count;
// using (MAction action = new MAction("Users.txt", "Txt Path={0}"))
// {
// //從文件中獲取內容
// action.Select(pagerControl2.PageIndex, pagerControl2.PageSize, string.Empty, out count).Bind(dataGridView1);
// System.Diagnostics.Debug.WriteLine(pagerControl2.PageIndex + "---"+ pagerControl2.Size);
// System.Diagnostics.Debug.WriteLine(""+count);
// //LogUtils.AddUpdateLog("ERROR","日志工具");
// if (count < 10) {
// }
// else
// {
// pagerControl2.DrawControl(count);
// }
// }
//}
/// <summary>
/// 創建文件件數據庫表 并插入數據
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StartForm_Load(object sender, EventArgs e)
{
//創建文件數據庫表。
MDataTable.CreateSchema("Users.txt", false, new string[] { "TiMing", "PassWord", "Enabled" }, SqlDbType.NText, SqlDbType.NText, SqlDbType.NText);
for (int i = 0; i < 200; i++)//插入200條數據。
{
using (MAction action = new MAction("Users.txt", "Txt Path={0}"))
{
action.Set("TiMing", "題名" + i);
action.Set("PassWord", "密碼" + i);
action.Set("Enabled", i % 2 == 0);
action.Insert(InsertOp.None);
}
}
//MessageBox.Show("ddd","ddd");
pagerControl1.OnPageChanged += new EventHandler(pagerControl1_OnPageChanged);
LoadData();
}
CYQ的相關文檔
一款相當給力的數據庫操作組件
用MDataColumns 復制表結構并創建新的表
string conn = "數據庫連接串";
using (MAction action = new MAction("test", conn)) {
mdc = action.Data.Columns;
}
bool a = DBTool.CreateTable("test2",mdc,conn);
自己指定字段創建新表
string conn = "數據庫連接串";
mdc = new MDataColumn();
mdc.Add("測試字段",SqlDbType.Text);
mdc.Add("測試字段2",SqlDbType.Text);
mdc.Add("測試字段3",SqlDbType.Text);
mdc.Add("測試字段4",SqlDbType.Text);
mdc.Add("測試字段5",SqlDbType.Text);
mdc.Add("測試字段6",SqlDbType.Text);
bool a = DBTool.CreateTable("TEST3",mdc,conn);
if (a)
{
MessageBox.Show("success");
}
else {
MessageBox.Show("failed");
}
.net 中沒有 ConfigurationManager 解決辦法
在引用的文件夾右鍵添加引用,選擇程序集,搜索 configuration 勾選確定即可
從配置文件中讀取 配置
<connectionStrings>
<add name="strCon"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Database1.accdb"
providerName="System.Data.OleDb" />
</connectionStrings>
<appSettings>
<add key="aaa" value="bbb"/>
</appSettings>
string conn = ConfigurationManager.ConnectionStrings["strCon"].ToString();
string conn = ConfigurationManager.AppSettings["aaa"];
第一種 關閉當前窗口,并開啟新的窗口 (使用的時候提示過時,原理是開啟一個新的線程去啟動這個窗口)
BookSellerMain bsm = new BookSellerMain();
//賬號、密碼驗證通過后,執行以下代碼
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));
#pragma warning disable CS0618 // 類型或成員已過時
t.ApartmentState = System.Threading.ApartmentState.STA;
#pragma warning restore CS0618 // 類型或成員已過時
t.Start();
bsm.myevent += new BookSellerMain.dd(BookSellerMain_myevent);
this.Close();
第二種 (也有人說 無法關閉當前窗口,并開啟新的窗口)
//兩個窗口form1和form2
//點擊form1中的一個按鈕,打開form2同時關閉form1
form2 f2 = new form2();
f2.show();
this.close(); //也可以直接 close();
(注意:如果form1是主窗口。不可以close只能hide ,即this.hide())
若要退出當前程序:Application.exit();
點擊右上角關閉觸發的方法
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
/// MessageBox.Show("OnClosed");
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
// MessageBox.Show("OnFormClosing");
}
protected override void OnFormClosed(FormClosedEventArgs e)
{
base.OnFormClosed(e);
// MessageBox.Show("OnFormClosed");
}
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
// MessageBox.Show("OnClosing");
}