Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > C# ถามเรื่องเครื่องคิดเลขครับ คือผมสร้างเครื่องคิดเลขเฉพาะการบวกขึ้นครับ



 

C# ถามเรื่องเครื่องคิดเลขครับ คือผมสร้างเครื่องคิดเลขเฉพาะการบวกขึ้นครับ

 



Topic : 034407



โพสกระทู้ ( 8 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook



คือผมสร้างเครื่องคิดเลขเฉพาะการบวกขึ้นครับ ซึ่งหลักการเหมือนกับเครื่องคิดเลขทั่วไปๆ ซึ่งสามารถกดบวกเลขไปได้เรื่อยๆ ซึ่งข้อแตกต่างคือต้องเป็นการรับตัวเลขนั้นๆ มาจาก textbox อันเดียวครับ (โจทย์กำหนดมา) ผมทำได้แค่ให้มันรับมาแค่สองตัว ไม่ทราบจะมีวิธีไหนที่ให้มันรับตัวเลขได้ตลอดจนกว่าจะกดเคลียร์ครับ

นี่เป็นภาพโปรแกรมนะครับ
calculator

ส่วนนี่เป็นโค้ดของโปรแกรมตัวนี้ครับ
Code (C#)
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 test
{
    public partial class Form1 : Form
    {
        public static int x, y, z;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            x = Convert.ToInt32(textBox1.Text);
            textBox1.Clear();
            label1.Text = Convert.ToString(x);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            y = Convert.ToInt32(textBox1.Text);
            z=x + y;
            label1.Text =Convert.ToString(x)  + " + " + Convert.ToString(y) + " = " + Convert.ToString(z);
            //textBox1.Text=Convert.ToString(x);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            label1.Text = "";
        }
    }
}




Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-11-14 23:01:44 By : princecoffee View : 15656 Reply : 4
 

 

No. 1



โพสกระทู้ ( 179 )
บทความ ( 0 )



สถานะออฟไลน์


พอดี เขียน WinApp ไม่เป็นเลนเขียน C# WebApp มาให้นะครับ ลองประยุกดูและกัน เพราะ WebApp ผมจะใช้ Session ด้วย ไม่รู้ WinApp ใช้อะไร ^^

หน้า aspx
Code (C#)
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;<asp:Label ID="Label2" runat="server"></asp:Label>
    <asp:Label ID="Label1" runat="server"></asp:Label><br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="btn_up" runat="server" Text="Insert" OnClick="btn_up_Click" />
        <asp:Button ID="btn_Add" runat="server" Text="+" OnClick="btn_Add_Click" />
        <asp:Button ID="btn_result" runat="server" Text="=" OnClick="btn_result_Click" />
        </div>
    </form>
</body>


Code Behind
Code (C#)
using System.Collections.Generic;
public partial class Calculate : System.Web.UI.Page
{   
    public ArrayList inputData = new ArrayList();
    int result = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (Session["data"] != null)
        {
            inputData = (ArrayList)Session["data"];

        }
        if (Session["result"] != null)
        {
            result = (int)Session["result"];
        }
       
       
    }
    
    protected void btn_up_Click(object sender, EventArgs e)
    {
        inputData.Add(TextBox1.Text);
        int index = inputData.Count;
        if (index >= 3)
        {
            if (result == 0)
            {
                if (inputData[index - 2].ToString() == "+")
                {
                    result += System.Convert.ToInt32(inputData[index - 3].ToString()) + System.Convert.ToInt32(inputData[index - 1].ToString());
                    Session["result"] = result;

                }
            }
            else
            {
                result += System.Convert.ToInt32(inputData[index - 1].ToString());
                Session["result"] = result;
            }
        }
        
        Session["data"] = inputData;
        TextBox1.Text = "";
        Label2.Text = "";
        foreach (string a in inputData)
        {
            //Label1.Text +=""+ a;
            Label2.Text += "" + a;

        }

    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        inputData.Add("+");
        Session["data"] = inputData;
        TextBox1.Text = "";
        Label2.Text = "";
        foreach (string a in inputData)
        {
            //Label1.Text +=""+ a;
            Label2.Text += "" + a;

        }
    }
    protected void btn_result_Click(object sender, EventArgs e)
    {
        inputData = (ArrayList)Session["data"];
        foreach(string a in inputData)
        {
            //Label1.Text +=""+ a;
            Label1.Text = "=" + result;

        }
    }
}







Date : 2009-11-19 13:48:04 By : ksillapapan
 


 

No. 2

Guest


Code (C#)
        private string number(string N)
        {
            if (textBox1.Text == "0")
                return N;
            else if (btnResult.Enabled == true)
                return textBox1.Text + N;
            else
            {
                btnResult.Enabled = true;
                listBox1.Items.Clear();
                return N;
            }


Date : 2011-12-16 14:55:07 By : kkkkk
 

 

No. 3

Guest


อันนี้ บวก ลบ คูณ หาร ได้

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
//int a;
bool plus = false;
bool minus = false;
bool multiply = false;
bool divide = false;
bool power = false;
public Form1()
{
InitializeComponent();
}

private void num_0_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "0";
}

private void num_1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "1";
}

private void num_2_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "2";
}

private void num_3_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "3";
}

private void num_4_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "4";
}

private void num_5_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "5";
}

private void num_6_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "6";
}

private void num_7_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "7";
}

private void num_8_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "8";
}

private void num_9_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "9";
}

private void btnBackspace_Click(object sender, EventArgs e)
{
int a = textBox1.Text.Length;
if (textBox1.Text == "")
{
textBox1.Text = "";
}

else
{
textBox1.Text = textBox1.Text.Remove(a - 1);
}
}

private void button1_Click(object sender, EventArgs e)
{
if (plus)
{

decimal dec = Convert.ToDecimal(textBox1.Tag) + Convert.ToDecimal(textBox1.Text);

textBox1.Text = dec.ToString();

}

else if (minus)
{

decimal dec = Convert.ToDecimal(textBox1.Tag) - Convert.ToDecimal(textBox1.Text);

textBox1.Text = dec.ToString();

}

else if (multiply)
{

decimal dec = Convert.ToDecimal(textBox1.Tag) * Convert.ToDecimal(textBox1.Text);

textBox1.Text = dec.ToString();

}

else if (divide)
{

if (textBox1.Text == "0")
{

textBox1.Text = "0";

}

else if (textBox1.Text != "0")
{

decimal dec = Convert.ToDecimal(textBox1.Tag) / Convert.ToDecimal(textBox1.Text);

textBox1.Text = dec.ToString();

}

}

else if (power)
{

decimal dec = Convert.ToDecimal(textBox1.Tag) * Convert.ToDecimal(textBox1.Tag);

textBox1.Text = dec.ToString();
}




return;

}

private void btnKoon_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{

return;

}

else
{

multiply = true;

textBox1.Tag = textBox1.Text;

textBox1.Text = "";


}
}

private void btnLopp_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{

return;

}

else
{

minus = true;

textBox1.Tag = textBox1.Text;

textBox1.Text = "";
}
}

private void btnBuak_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{

return;

}

else
{

plus = true;

textBox1.Tag = textBox1.Text;

textBox1.Text = "";
}
}

private void btnHan_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
return;
}

else
{
divide = true;
textBox1.Tag = textBox1.Text;
textBox1.Text = "";
}
}

private void btnClear_Click(object sender, EventArgs e)
{
textBox1.Text = "";
}

private void btnJud_Click(object sender, EventArgs e)
{
if (textBox1.Text.Contains("."))
{
return;
}
else
{
textBox1.Text = textBox1.Text + ".";
}
}
}
เอามาให้ดูครับ ใช่ได้เลย เห็นว่า ปีหนึ่งต้องใช่มัน ผมไม่เก่งหรอกแต่ อัลลกอล์ ผมแน่น เลยทำได้ ลองให้เพื่อนฝึกอัลกอล์ดูนะครับ
Date : 2012-09-14 15:28:36 By : narutoyah
 


 

No. 4

Guest


int a = "'+ textBox10.Text +'";
int b = "'+ textBox9.Text +'";
int z = a + b;
Date : 2014-03-14 23:41:36 By : ดนั
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : C# ถามเรื่องเครื่องคิดเลขครับ คือผมสร้างเครื่องคิดเลขเฉพาะการบวกขึ้นครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่