2016年6月2日 星期四

JAVAscript

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>第一支javaScript</title>
</head>
<body>
<h2>document.write用法</h2>
<Script type ="text/javascript">
document.write("Hello world!!");
</Script>
</body>
</html>



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>第一支javaScript</title>
</head>
<body>
<h2>document.write用法</h2>
<Script type ="text/javascript">
document.write("Hello world!!");
function myMsg(myObj){

alert("id 為: " + myObj.id);
}
</Script>
<input type="button" id="myButton" name="mybutton" value="送出" onclick="myMsg(this)">
</body>
</html>



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>第一支javaScript</title>
</head>
<body>
<h2>document.write用法</h2>
<Script type ="text/javascript">
document.write("Hello world!!");
</Script>
<form action="#" method="post" class="demoForm" id="demoForm">
<fieldset>
<legend>Demo: Get Value of Selected</legend>

<p>Select a shipping method:</p>
<p>
<label><input type="radio" name="ship" value="A" checked /> (A)Standard Ground</label>
<label><input type="radio" name="ship" value="B" /> (B)Second Day</label>
<label><input type="radio" name="ship" value="C" /> (C)Overnight</label>
<label><input type="radio" name="ship" value="D" /> (D)Pick up</label>
</p>

<p><button type="button" name="getVal">Get Value of Selected</button></p>

</fieldset>
</form>
<script type="text/javascript">
// to remove from global namespace
(function() {

function getRadioVal(form, name) {
var val;
var radios = form.elements[name];

for (var i=0, len=radios.length; i<len; i++) {
if ( radios[i].checked ) {
val = radios[i].value;
break;
}
}
return val;
}

document.forms['demoForm'].elements['getVal'].onclick = function() {
alert( 'The selected radio button\'s value is: ' + getRadioVal(this.form, 'ship') );
};


// disable submission of all forms on this page
for (var i=0, len=document.forms.length; i<len; i++) {
document.forms[i].onsubmit = function() { return false; };
}

}());
</script>
</body>
</html>

script

<!DOCTYPE html >
<html >
<head>
    <title>加法運算器</title>
    <script>
        function add() {
            var a = parseInt(document.getElementById('a').value);
            var b = parseInt(document.getElementById('b').value);
            document.getElementById('result').value =  a+b ;
        }
    </script>
</head>
<body>
    <input id="a" type="text" />+<input id="b" type="text" />
    <button onclick="add()" >=</button>
    <output id="result"></output>
</body>
</html>


<!DOCTYPE html ><html >
<head>
    <title>
    Form
    </title>
<script>
function check1() {
 var radio1=document.getElementsByName("v1");
 var radio2=document.getElementsByName("v2");
var radio3=document.getElementsByName("v3");
var radio4=document.getElementsByName("v4");
var radio5=document.getElementsByName("v5");
var radio6=document.getElementsByName("v6");
var radio7=document.getElementsByName("v7");
var radio8=document.getElementsByName("v8");
var radio9=document.getElementsByName("v9");
var radio10=document.getElementsByName("v10");
   for(var i=0;i<radio1.length;i++){
     if(radio1.item(i).checked==true)        {
       flag1=i+1;
       alert(radio1.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio2.length;i++){
     if(radio2.item(i).checked==true)        {
       flag2=i+1;
     
       alert(radio2.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio3.length;i++){
     if(radio3.item(i).checked==true)        {
       flag3=i+1;
       alert(radio3.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio4.length;i++){
     if(radio4.item(i).checked==true)        {
       flag4=i+1;
       alert(radio4.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio5.length;i++){
     if(radio5.item(i).checked==true)        {
       flag5=i+1;
       alert(radio5.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio6.length;i++){
     if(radio6.item(i).checked==true)        {
       flag6=i+1;
       alert(radio6.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio7.length;i++){
     if(radio7.item(i).checked==true)        {
       flag7=i+1;
       alert(radio7.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio8.length;i++){
     if(radio8.item(i).checked==true)        {
       flag8=i+1;
       alert(radio8.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio9.length;i++){
     if(radio9.item(i).checked==true)        {
       flag9=i+1;
       alert(radio9.item(i).value);
                  break;
       }
   }
 for(var i=0;i<radio10.length;i++){
     if(radio10.item(i).checked==true)        {
       flag10=i+1;
       alert(radio10.item(i).value);
                  break;
       }
   }
document.write(flag1,flag2,flag3,flag4,flag5,flag6,flag7,flag8,flag9,flag10,"<br>");
document.write(flag1+flag2+flag3+flag4+flag5+flag6+flag7+flag8+flag9+flag10,"<br>");
}
</script>
</head>
<body>
  <h1>1、ssss?</h1>
<input name="v1" type="radio" value="1.1">300年             
<input name="v1" type="radio" value="1.2">400年               
<input name="v1" type="radio" value="1.3">1000年
<h1>1、ssss?</h1>
<input name="v2" type="radio" value="2.1">300年             
<input name="v2" type="radio" value="2.2">400年               
<input name="v2" type="radio" value="2.3">1000年
<h1>1、ssss?</h1>
<input name="v3" type="radio" value="1.1">300年             
<input name="v3" type="radio" value="1.2">400年               
<input name="v3" type="radio" value="1.3">1000年
<h1>1、ssss?</h1>
<input name="v4" type="radio" value="1.1">300年             
<input name="v4" type="radio" value="1.2">400年               
<input name="v4" type="radio" value="1.3">1000年
<h1>1、ssss?</h1>
<input name="v5" type="radio" value="1.1">300年             
<input name="v5" type="radio" value="1.2">400年               
<input name="v5" type="radio" value="1.3">1000年
<h1>1、ssss?</h1>
<input name="v6" type="radio" value="1.1">300年             
<input name="v6" type="radio" value="1.2">400年               
<input name="v6" type="radio" value="1.3">1000年
<h1>1、ssss?</h1>
<input name="v7" type="radio" value="1.1">300年             
<input name="v7" type="radio" value="1.2">400年               
<input name="v7" type="radio" value="1.3">1000年
<h1>1、ssss?</h1>
<input name="v8" type="radio" value="1.1">300年             
<input name="v8" type="radio" value="1.2">400年               
<input name="v8" type="radio" value="1.3">1000年
<h1>1、ssss?</h1>
<input name="v9" type="radio" value="1.1">300年             
<input name="v9" type="radio" value="1.2">400年               
<input name="v9" type="radio" value="1.3">1000年
<h1>1、ssss?</h1>
<input name="v10" type="radio" value="1.1">300年             
<input name="v10" type="radio" value="1.2">400年               
<input name="v10" type="radio" value="1.3">1000年
<input type="button" value="submit" onclick="check1()"/>
</form>
</body>
</html>


出題目 文字方塊顯示

<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
    google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);
 var a ;
 var b ;
 var c ;
function add() {
a=0;
b=0;
c=0;
var radio1=document.getElementsByName("v1");
var radio2=document.getElementsByName("v2");
var radio3=document.getElementsByName("v3");
 for(var i=0;i<radio1.length;i++){
     if(radio1.item(i).checked==true)        {
       i=i+1;
       alert(i);
if(i==1){
       a=a+1;
}
else 
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       }
   }

for(var i=0;i<radio2.length;i++){
     if(radio2.item(i).checked==true)        {
       i=i+1;
       alert(i);
       if(i==1){
       a=a+1;
}
else 
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       }
   }
for(var i=0;i<radio3.length;i++){
     if(radio3.item(i).checked==true)        {
       i=i+1;
       alert(i);
       if(i==1){
       a=a+1;
}
else 
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       }
   }
            drawChart();
        }   

        function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     a],
          ['Eat',      b],
          ['Commute',  c],
        ]);
        var options = {
          title: 'My Daily Activities'
        };
        var chart = new google.visualization.PieChart(document.getElementById('piechart'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
<h1>1、ssss?</h1>
<input name="v1" type="radio" value="1.1">300年             
<input name="v1" type="radio" value="1.2">400年               
<input name="v1" type="radio" value="1.3">1000年
<br>
<h1>2、ssss?</h1>
<input name="v2" type="radio" value="1.1">300年             
<input name="v2" type="radio" value="1.2">400年               
<input name="v2" type="radio" value="1.3">1000年
<br>
<h1>3、ssss?</h1>
<input name="v3" type="radio" value="1.1">300年             
<input name="v3" type="radio" value="1.2">400年               
<input name="v3" type="radio" value="1.3">1000年
<br>
c1:
<input type="text" name="FirstName" id="c1"<br><br/>
c2:
<input type="text" name="address" id="c2"<br><br/>
c3:
<input type="text" name="address" id="c3"<br><br/>

    <input type="button" value="submit" onclick="add()"/>
    <div id="piechart" style="width: 900px; height: 500px;"></div>
  </body>
</html>


隨機亂數選題

<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
    google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);
 var a ;
 var b ;
 var c ;
function add() {
a=0;
b=0;
c=0;
var radio1=document.getElementsByName("v1");
var radio2=document.getElementsByName("v2");
var radio3=document.getElementsByName("v3");
var radio4=document.getElementsByName("v4");
var radio5=document.getElementsByName("v5");
var radio6=document.getElementsByName("v6");
var radio7=document.getElementsByName("v7");
var radio8=document.getElementsByName("v8");
var radio9=document.getElementsByName("v9");
var radio10=document.getElementsByName("v10");
 for(var i=0;i<radio1.length;i++){
     var maxNum = 3;  
var minNum = 1;  
var i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;   
 v1= i;
       alert(i);
if(i==1){
       a=a+1;
}
else 
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
      
   }

for(var i=0;i<radio2.length;i++){
     radio2.item(i)==true
      var maxNum = 3;  
var minNum = 1;  
var i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;   
       alert(i);
       if(i==1){
       a=a+1;
}
else 
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       
   }
for(var i=0;i<radio3.length;i++){
        var maxNum = 3;  
var minNum = 1;  
var i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;   
       alert(i);
       if(i==1){
       a=a+1;
}
else 
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       
   }
for(var i=0;i<radio4.length;i++){
        var maxNum = 3;  
var minNum = 1;  
var i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;   
       alert(i);
if(i==1){
       a=a+1;
}
else 
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       
   }
for(var i=0;i<radio5.length;i++){
          var maxNum = 3;  
var minNum = 1;  
var i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;   
       alert(i);
if(i==1){
       a=a+1;
}
else 
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       
   }
for(var i=0;i<radio6.length;i++){
         var maxNum = 3;  
var minNum = 1;  
var i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;   
       alert(i);
if(i==1){
       a=a+1;
}
else 
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       
   }
for(var i=0;i<radio7.length;i++){
         var maxNum = 3;  
var minNum = 1;  
var i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;   
       alert(i);
if(i==1){
       a=a+1;
}
else 
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       
   }
for(var i=0;i<radio8.length;i++){
         var maxNum = 3;  
var minNum = 1;  
var i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;   
       alert(i);
if(i==1){
       a=a+1;
}
else 
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       
   }
for(var i=0;i<radio9.length;i++){
        var maxNum = 3;  
var minNum = 1;  
var i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;   
       alert(i);
if(i==1){
       a=a+1;
}
else 
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       
   }
for(var i=0;i<radio10.length;i++){
          var maxNum = 3;  
var minNum = 1;  
var i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
i = Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;   
       alert(i);
if(i==1){
       a=a+1;
}
else 
    if(i==2) {
        b=b+1;
    }
    else {
        c=c+1;
    }
document.getElementById('c1').value=a;
document.getElementById('c2').value=b;
document.getElementById('c3').value=c;
                  break;
       
   }
            drawChart();
        }   

        function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['同意',     a],
          ['不同意',      b],
          ['沒意見',  c],
        ]);
        var options = {
          title: 'My Daily Activities'
        };
        var chart = new google.visualization.PieChart(document.getElementById('piechart'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
<h1>1、ssss?</h1>
<input name="v1" type="radio" value="1.1">同意             
<input name="v1" type="radio" value="1.2">不同意               
<input name="v1" type="radio" value="1.3">沒意見
<br>
<h1>2、ssss?</h1>
<input name="v2" type="radio" value="1.1">同意             
<input name="v2" type="radio" value="1.2">不同意               
<input name="v2" type="radio" value="1.3">沒意見
<br>
<h1>3、ssss?</h1>
<input name="v3" type="radio" value="1.1">同意             
<input name="v3" type="radio" value="1.2">不同意              
<input name="v3" type="radio" value="1.3">沒意見
<br>
<h1>4、ssss?</h1>
<input name="v4" type="radio" value="1.1">同意            
<input name="v4" type="radio" value="1.2">不同意            
<input name="v4" type="radio" value="1.3">沒意見
<br>
<h1>5、ssss?</h1>
<input name="v5" type="radio" value="1.1">同意            
<input name="v5" type="radio" value="1.2">不同意            
<input name="v5" type="radio" value="1.3">沒意見
<br>
<h1>6、ssss?</h1>
<input name="v6" type="radio" value="1.1">同意            
<input name="v6" type="radio" value="1.2">不同意            
<input name="v6" type="radio" value="1.3">沒意見
<br>
<h1>7、ssss?</h1>
<input name="v7" type="radio" value="1.1">同意            
<input name="v7" type="radio" value="1.2">不同意              
<input name="v7" type="radio" value="1.3">沒意見
<br>
<h1>8、ssss?</h1>
<input name="v8" type="radio" value="1.1">同意           
<input name="v8" type="radio" value="1.2">不同意             
<input name="v8" type="radio" value="1.3">沒意見
<br>
<h1>9、ssss?</h1>
<input name="v9" type="radio" value="1.1">同意             
<input name="v9" type="radio" value="1.2">不同意               
<input name="v9" type="radio" value="1.3">沒意見
<br>
<h1>10、ssss?</h1>
<input name="v10" type="radio" value="1.1">同意           
<input name="v10" type="radio" value="1.2">不同意              
<input name="v10" type="radio" value="1.3">沒意見
<br>
同意:
<input type="text" name="FirstName" id="c1"<br><br/>
不同意:
<input type="text" name="address" id="c2"<br><br/>
沒意見:
<input type="text" name="address" id="c3"<br><br/>

    <input type="button" value="submit" onclick="add()"/>
    <div id="piechart" style="width: 900px; height: 500px;"></div>
  </body>
</html>



九宮格

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 { partial class Form1 { /// <summary> /// 設計工具所需的變數。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清除任何使用中的資源。 /// </summary> /// <param name="disposing">如果應該處置 Managed 資源則為 true,否則為 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form 設計工具產生的程式碼 /// <summary> /// 此為設計工具支援所需的方法 - 請勿使用程式碼編輯器 /// 修改這個方法的內容。 /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.button5 = new System.Windows.Forms.Button(); this.button6 = new System.Windows.Forms.Button(); this.button7 = new System.Windows.Forms.Button(); this.button8 = new System.Windows.Forms.Button(); this.button9 = new System.Windows.Forms.Button(); this.button10 = new System.Windows.Forms.Button(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(0, 0); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(86, 66); this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; // // button2 // this.button2.Location = new System.Drawing.Point(83, 0); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(86, 66); this.button2.TabIndex = 1; this.button2.Text = "button2"; this.button2.UseVisualStyleBackColor = true; // // button3 // this.button3.Location = new System.Drawing.Point(166, 0); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(86, 66); this.button3.TabIndex = 2; this.button3.Text = "button3"; this.button3.UseVisualStyleBackColor = true; // // button4 // this.button4.Location = new System.Drawing.Point(0, 61); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(86, 66); this.button4.TabIndex = 3; this.button4.Text = "button4"; this.button4.UseVisualStyleBackColor = true; // // button5 // this.button5.Location = new System.Drawing.Point(83, 61); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(86, 66); this.button5.TabIndex = 4; this.button5.Text = "button5"; this.button5.UseVisualStyleBackColor = true; // // button6 // this.button6.Location = new System.Drawing.Point(166, 61); this.button6.Name = "button6"; this.button6.Size = new System.Drawing.Size(86, 66); this.button6.TabIndex = 5; this.button6.Text = "button6"; this.button6.UseVisualStyleBackColor = true; // // button7 // this.button7.Location = new System.Drawing.Point(0, 124); this.button7.Name = "button7"; this.button7.Size = new System.Drawing.Size(86, 66); this.button7.TabIndex = 6; this.button7.Text = "button7"; this.button7.UseVisualStyleBackColor = true; // // button8 // this.button8.Location = new System.Drawing.Point(83, 124); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(86, 66); this.button8.TabIndex = 7; this.button8.Text = "button8"; this.button8.UseVisualStyleBackColor = true; // // button9 // this.button9.Location = new System.Drawing.Point(166, 124); this.button9.Name = "button9"; this.button9.Size = new System.Drawing.Size(86, 66); this.button9.TabIndex = 8; this.button9.Text = "button9"; this.button9.UseVisualStyleBackColor = true; // // button10 // this.button10.Location = new System.Drawing.Point(338, 263); this.button10.Name = "button10"; this.button10.Size = new System.Drawing.Size(106, 82); this.button10.TabIndex = 10; this.button10.Text = "button10"; this.button10.UseVisualStyleBackColor = true; this.button10.Click += new System.EventHandler(this.button10_Click); // // pictureBox1 // this.pictureBox1.BackgroundImage = global::WindowsFormsApplication1.Properties.Resources._12202063_829626943802170_812264383_n; this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.pictureBox1.Location = new System.Drawing.Point(56, 227); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(220, 188); this.pictureBox1.TabIndex = 9; this.pictureBox1.TabStop = false; this.pictureBox1.UseWaitCursor = true; this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(488, 448); this.Controls.Add(this.button10); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.button9); this.Controls.Add(this.button8); this.Controls.Add(this.button7); this.Controls.Add(this.button6); this.Controls.Add(this.button5); this.Controls.Add(this.button4); this.Controls.Add(this.button3); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.Button button4; private System.Windows.Forms.Button button5; private System.Windows.Forms.Button button6; private System.Windows.Forms.Button button7; private System.Windows.Forms.Button button8; private System.Windows.Forms.Button button9; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Button button10; } }


陣列數字排序

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 WindowsFormsApplication4 { public partial class Form1 : Form { Button[,] Buttons = new System.Windows.Forms.Button[5, 5]; int[] randomize = new int[5]; //宣告一個一維陣列 (用來存取變數的陣列) Random rnd = new Random(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { for (int i = 1; i < 5; i++) { for (int j = 1; j < 5; j++) { Buttons[i, j] = new Button(); Buttons[i, j].Size = new Size(50, 50); Buttons[i, j].Location = new Point(i * 50, j * 50); this.Controls.Add(Buttons[i, j]);//出現在畫面中 } } } private void button1_Click(object sender, EventArgs e) { int pro = 0, a = 0, b = 0, c = 0; for (int i = 1; i < 5; i++) { for (int j = 1; j < 5; j++) { pro = i; a = i + 4; b = i + 8; c = i + 12; Buttons[i, 1].Text = pro.ToString(); Buttons[i, 2].Text = a.ToString(); Buttons[i, 3].Text = b.ToString(); Buttons[i, 4].Text = c.ToString(); } } } } }

拉霸

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 { int c1 = 0, c2 = 0, c3 = 0, d1 = 0, d2 = 0, d3 = 0, radmoney1 = 100, radmoney2 = 100, radmoney3 = 100; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button4_Click(object sender, EventArgs e) { c1 = 0; c2 = 0; c3 = 0; d1 = 1; d2 = 2; d3 = 0; timer1.Enabled = true; timer2.Enabled = true; timer3.Enabled = true; Random rnd = new Random(); radmoney1 = rnd.Next(1, 101); radmoney2 = rnd.Next(1, 101); radmoney3 = rnd.Next(1, 101); button4.Text = radmoney1.ToString() + radmoney2.ToString() + radmoney3.ToString(); } private void timer1_Tick(object sender, EventArgs e) { c1 = c1 + 1; d1 = c1 % 2; if (c1 >= radmoney1) timer1.Enabled = false; button1.Text = d1.ToString(); } private void timer2_Tick(object sender, EventArgs e) { c2 = c2 + 1; d2 = c2 % 2; if (c2 >= radmoney2) timer2.Enabled = false; button2.Text = d2.ToString(); } private void timer3_Tick(object sender, EventArgs e) { c3 = c3 + 1; d3 = c3 % 2; if (c3 >= radmoney3) timer3.Enabled = false; button3.Text = d3.ToString(); } private void timer4_Tick(object sender, EventArgs e) { button4.Text = "start"; if (d1 == d2 && d2 == d3) { button5.Text = "win"; } else { button5.Text = "flaut"; } } } }