網誌
【WordPress】除去頁面的邊欄
There are times when you want to remove or disable your sidebar for a specific page or post in WordPress. Maybe you host a giveaway or a product review and one of your Ad Networks won’t allow your post to appear on the same page as their ad. This article describes several methods to disable …
【程式設計-C#】設計小算盤
計算機軟體
Windows 7上的小算盤
Windows 10上的小算盤
講解-1:程式設計 20180417 3 計算機程式 共用事件
講解-2: 程式設計 20180501 1 計算機程式 加減乘除
【程式碼】
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Calculator { public partial class Form1 : Form { int op1, op2; char op; bool 是否清除輸入方塊 = false; public Form1() { InitializeComponent(); } private void 數字鍵_Click(object sender, EventArgs e) { Button btn = (Button)sender; if (是否清除輸入方塊) { label1.Text = "0"; 是否清除輸入方塊 = false; } if (label1.Text == "0") label1.Text = btn.Text; else label1.Text += btn.Text; } private void 加減乘除_Click(object sender, EventArgs e) { Button btn = (Button)sender; op = Convert.ToChar(btn.Text); op1 = Convert.ToInt32(label1.Text); 是否清除輸入方塊 = true; } private void 計算結果_Click(object sender, EventArgs e) { op2 = Convert.ToInt32(label1.Text); switch (op) { case '+': label1.Text = "" + (op1 + op2); break; case '-': label1.Text = "" + (op1 - op2); break; case '*': label1.Text = "" + (op1 * op2); break; case '/': label1.Text = "" + (op1 / op2); break; } } } }
提示 – 倒退鍵的處理:
label1.text = label1.text.Substring( 0, labe
【程式設計】【C#】使用OpenFileDialog來開啟文字檔案
程式專案下載:openTextFile
程式中的元件:
1.OpenFileDialog
2.Button
3.TextBox,名稱設寫tbResult,多行,垂直scrollbar
程式碼:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // 建立一個OpenFileDialog物件 OpenFileDialog openFileDialog1 = new OpenFileDialog(); // 設定OpenFileDialog屬性 openFileDialog1.Title = "選擇要開啟的文字檔案"; openFileDialog1.Filter = "Text Files (.txt)|*.txt|All Files (*.*)|*.*"; openFileDialog1.FilterIndex = 1; openFileDialog1.Multiselect = true; // 喚用ShowDialog方法,打開對話方塊 if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string theFile = openFileDialog1.FileName; //取得檔名 Encoding enc = Encoding.GetEncoding("big5"); //設定檔案的編碼 tbResult.Text = System.IO.File.ReadAllText(theFile, enc); //以指定的編碼方式讀取檔案 } } } }
說實話的校長和講好聽話的里長…一個故事告訴你:從不缺說真話的人,但缺一張會說鬼話的嘴 (里長,校長,權重,職責,學校,西裝,行銷,…) – 職場力 – 職場修練 – 記帳士的商管筆記 – 商業周刊 – 商周.com
過河問題:農夫、羊、狼、青菜
一名農夫帶著一隻狼、一隻羊和一顆高麗菜渡河,河上只有一艘船,一次只能載農夫和一樣東西到對岸,只有農夫會/能划船,如果農夫沒看著,狼會吃羊,羊會吃菜,農夫要如何成功的將狼、羊、高麗菜帶到另一岸,而不會有損失?
程式畫面
【程式列表】
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { string farmerLocation = "L"; //農夫的位置,一開始在左邊 public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { lstBoxL.Enabled = true; L.Text = "西岸(可選取)"; lstBoxR.Enabled = false; R.Text = "東岸(不可選取)"; } /* * 當按了往右邊移動,有三個狀況: * 1.若農夫已在右邊,不需要移動,離開 * 2.只有農夫自己一人過河 * 3.農夫帶著一物過河,選取的物品從左邊移入右邊(Add),並從左邊移除(Remove) * * 2與3共同步驟: * 設定農夫位值在右邊 * 對調左右2個清單方塊的可選取狀態 */ private void btn2Right_Click(object sender, EventArgs e) //按下往右移動 { if (farmerLocation == "R") return; //如果農夫已在右邊的話就離開 if (lstBoxL.SelectedItem != null) //若左邊方塊有選取 { lstBoxR.Items.Add(lstBoxL.SelectedItem); //將左邊方塊的選取項目加到右邊方塊 lstBoxL.Items.Remove(lstBoxL.SelectedItem); //將左邊方塊選取項目移除掉(移到另一邊的意思) } lstBoxL.Enabled = false; L.Text = "西岸(不可選取)"; lstBoxR.Enabled = true; R.Text = "東岸(可選取)"; btnFarmer.Location = new Point(312, 120); //移動農夫 farmerLocation = "R"; //標記農夫的位置在右邊 } private void btn2Left_Click(object sender, EventArgs e) { if (farmerLocation == "L") return; //如果農夫已在右邊的話就離開 if (lstBoxR.SelectedItem != null) { lstBoxL.Items.Add(lstBoxR.SelectedItem); lstBoxR.Items.Remove(lstBoxR.SelectedItem); } lstBoxR.Enabled = false; R.Text = "東岸(不可選取)"; lstBoxL.Enabled = true; L.Text = "西岸(可選取)"; btnFarmer.Location = new Point(192, 120); farmerLocation = "L"; } private void button1_Click(object sender, EventArgs e) { //取消二邊清單方塊的選取 lstBoxL.SelectedItem = null; lstBoxR.SelectedItem = null; } } }
【程式英文】
1.ListBox 清單方塊
2.Item 項目 (清單方塊裏的)
3.Items 項目集合
4.Enabled 啟用的
5.SelectedItem 選取的項目
6.null 未指定/空
7.Location 位置
8.point 點
【遊戲判斷】
1.測試清單方塊裏的項目是否同時出現? 當農夫在另一邊時,此時,遊戲失敗!
a.羊和高麗菜,羊會吃了高麗菜
b.狼和羊,狼會吃了羊
2.若羊、狼、高麗菜同時出現在右邊清單方塊時,此時,遊戲過關!
【程式判斷是否失敗】
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { string farmerLocation = "L"; //農夫的位置,一開始在左邊 public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { lstBoxL.Enabled = true; L.Text = "西岸(可選取)"; lstBoxR.Enabled = false; R.Text = "東岸(不可選取)"; } private void lstBoxL_SelectedIndexChanged(object sender, EventArgs e) { } private bool isGameFailed() { bool hasSheep = false, hasWolf = false, hasCab = false; if (farmerLocation == "L") { foreach (object o in lstBoxR.Items) { string s = o.ToString(); if (s == "羊") hasSheep = true; if (s == "狼") hasWolf = true; if (s == "高麗菜") hasCab = true; } } else { foreach (object o in lstBoxL.Items) { string s = o.ToString(); if (s == "羊") hasSheep = true; if (s == "狼") hasWolf = true; if (s == "高麗菜") hasCab = true; } } bool gameFailed = false; if (hasSheep && hasCab) gameFailed = true; if (hasSheep && hasWolf) gameFailed = true; return gameFailed; } private void btn2Left_Click(object sender, EventArgs e) { if (farmerLocation == "L") return; //如果農夫已在右邊的話就離開 if (lstBoxR.SelectedItem != null) { lstBoxL.Items.Add(lstBoxR.SelectedItem); lstBoxR.Items.Remove(lstBoxR.SelectedItem); } lstBoxR.Enabled = false; R.Text = "東岸(不可選取)"; lstBoxL.Enabled = true; L.Text = "西岸(可選取)"; btnFarmer.Location = new Point(168, 101); farmerLocation = "L"; if (isGameFailed()) MessageBox.Show("You losed!"); } private void btn2Right_Click(object sender, EventArgs e) { if (farmerLocation == "R") return; //如果農夫已在右邊的話就離開 if (lstBoxL.SelectedItem != null) //若左邊方塊有選取 { lstBoxR.Items.Add(lstBoxL.SelectedItem); //將左邊方塊的選取項目加到右邊方塊 lstBoxL.Items.Remove(lstBoxL.SelectedItem); //將左邊方塊選取項目移除掉(移到另一邊的意思) } lstBoxL.Enabled = false; L.Text = "西岸(不可選取)"; lstBoxR.Enabled = true; R.Text = "東岸(可選取)"; btnFarmer.Location = new Point(312, 101); //移動農夫 farmerLocation = "R"; //標記農夫的位置在右邊 if (isGameFailed()) MessageBox.Show("You losed!"); } private void button1_Click(object sender, EventArgs e) { //取消二邊清單方塊的選取 lstBoxL.SelectedItem = null; lstBoxR.SelectedItem = null; } } }