Ok lets start with my problem:
First i have to write my date of birth with the following format: DD.MM.YYYY
This needs to be shown as DDMMYYYY, which means that dots must be lost. I've solved that.
This kind of number with 8 digits it needs to be converted in Binary and Hexadecimal digits.
I've done that to, all in console application.
My question is how to integrate that to wirk in a Form application. First TextBox I need to write my day of birth, in the second TextBox it mus be shown the fixed number without dots. In third one Converted to binary and in last one hexadecimal.

The code i wrote in Console application is as following:

namespace ConsoleApplication13
{
    class Program
    {
        
        static void Main(string[] args)
        {
            Console.WriteLine("Shkruaj datëlindjen tuaj");
            string sHyrje = Console.ReadLine();
            Console.WriteLine("Rregulluar: " + hyrja(sHyrje));
            Console.WriteLine("Binar: " + DecNeBin( int.Parse(hyrja(sHyrje))));
            Console.ReadLine();
            int a = int.Parse(hyrja(sHyrje));
            Console.WriteLine("Heksadecimal: "+a.ToString("X"));
            Console.ReadLine();
            
             
        }

        public static string DecNeBin(int a)
        {
            int hyrje = a;
            int[] a2 = new int[30];
            a2[0] = 1;

            int[] b2 = new int[30];
            b2[0] = hyrje % a2[0];

            int[] c2 = new int[30];

            string binar = "";
            
            for(int i=1; i<30; i++)
            {
                a2[i] = 2 * a2[i-1];
                b2[i] = hyrje % a2[i];
                c2[i - 1] = b2[i] / a2[i - 1];             

            }
            

            bool flag = false;
            for (int j = c2.Length; j > 0; j--)
            {
                if (c2[j-1] == 1)
                {
                    flag = true;
                }
                if (flag)
                {
                    binar = binar + c2[j-1];
                }

            }                        
            return binar;
        }
        public static string DecNeHex(int a)
        {
            return a.ToString("X");
        }
        public static string hyrja(string hyrje)
        {
            
            string sHyrje = hyrje;
            string sHyrjeRregulluar = "";
            char c;
            char[] cc;
            for (int i = 0; i < sHyrje.Length; i++)
            {
                // Console.WriteLine(i);
                c = char.Parse(sHyrje.Substring(i, 1));
                cc = sHyrje.ToCharArray(i, 1);
                try
                {
                    sHyrjeRregulluar = sHyrjeRregulluar + int.Parse(c.ToString());
                }
                catch { }

            }
            return sHyrjeRregulluar;
        }
    }
}

Recommended Answers

All 7 Replies

From this point, the easiest way would be to create a new WinForms project and then copy over all of the functions except for Main().

Set up pairs of textboxes on the form (left and right)
Have the first pair be the first conversion where you type in your DOB and on the "event" of either a button click or when you hit tab, the conversion function is called.

To avoid validation and problems with it, it is better to use a DateTimePicker on a form, to fill in a date.

To avoid validation and problems with it, it is better to use a DateTimePicker on a form, to fill in a date.

OK, I'm taking the date time picker but the problem is that I don't know how to make communication between buttons and text boxes.
Everything you do in console application you kan write something with Console.WriteLine or you can write something with Console.Write command.
How to make buttons intercommunicate with text boxes. The form must look like this.

[IMG]http://i444.photobucket.com/albums/qq165/dr_iton/form.jpg[/IMG]


Cheers.

The action is called an "Event"
If you're in the designer looking at your form, all you need to do is double-click the button and the IDE will create an event-handler for your "Event".

Inside that event handler (like a button click), you add the code to { do stuff } like put content in the text boxes (using the textBoxNme.Text property).

I just posted this snippet It may be helpful.

To elaborate on what thines01 already mentioned:
Start a new windowsform application.
In the designer, drop a TextBox and set the Name property(in the propezrtieswindow) to MyTextBox.
Drop a Button on the form.
Set the following properties: Name: ShowBtn and Text: Show
Now doubleclick the button in the designer, code for a Click EventHandler for the button will appear. Fill in code to set the Text property of the TextBox.
See the code for Form1.cs below:

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void ShowBtn_Click(object sender, EventArgs e)
        {
            // set the text property of the textbox with any string you want
            MyTextBox.Text = "Hello world!";
        }
    }
}

Try this out and see what happens. Success :)

At last I found a solution by my self after a hard work.

namespace Day_of_birth_converter
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonBinar_Click(object sender, EventArgs e)
        {
            try
            {
                textBoxDateLindjaRregulluar.Text = hyrja(textBoxDateLindja.Text);
                textBoxBinar.Text = DecNeBin(int.Parse(hyrja(textBoxDateLindjaRregulluar.Text)));
            }
            catch
            {
                MessageBox.Show("Ju lutem shkurani datëlindjen, nuk mund të kovertohet në BINAR!", 
                    "Gabim",
                    MessageBoxButtons.OK, 
                    MessageBoxIcon.Error);
            }
          }

        private void buttonHeksadecimal_Click(object sender, EventArgs e)
        {
             try
            {
            textBoxDateLindjaRregulluar.Text = hyrja(textBoxDateLindja.Text);
            textBoxHeksadecimal.Text = DecNeHex(int.Parse(textBoxDateLindjaRregulluar.Text));
            }
             catch
             {
                 MessageBox.Show("Ju lutem shkurani datëlindjen, nuk mund të konvertohet në HEKSADECIMAL!",
                     "Gabim",
                     MessageBoxButtons.OK,
                     MessageBoxIcon.Error);
             }
        }

        public static string DecNeBin(int a)
        {
            int hyrje = a;
            int[] a2 = new int[30];
            a2[0] = 1;

            int[] b2 = new int[30];
            b2[0] = hyrje % a2[0];

            int[] c2 = new int[30];

            string binar = "";

            for (int i = 1; i < 30; i++)
            {
                a2[i] = 2 * a2[i - 1];
                b2[i] = hyrje % a2[i];
                c2[i - 1] = b2[i] / a2[i - 1];

            }


            bool flag = false;
            for (int j = c2.Length; j > 0; j--)
            {
                if (c2[j - 1] == 1)
                {
                    flag = true;
                }
                if (flag)
                {
                    binar = binar + c2[j - 1];
                }

            }
            return binar;
        }
        public static string DecNeHex(int a)
        {
            return a.ToString("X");
        }
        public static string hyrja(string hyrje)
        {

            string sHyrje = hyrje;
            string sHyrjeRregulluar = "";
            char c;
            char[] cc;
            for (int i = 0; i < sHyrje.Length; i++)
            {
                
                c = char.Parse(sHyrje.Substring(i, 1));
                cc = sHyrje.ToCharArray(i, 1);
                try
                {
                    sHyrjeRregulluar = sHyrjeRregulluar + int.Parse(c.ToString());
                }
                catch{}

            }
            return sHyrjeRregulluar;
        }

        private void textBoxDateLindja_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }







    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.