Pages

‏إظهار الرسائل ذات التسميات c# code. إظهار كافة الرسائل
‏إظهار الرسائل ذات التسميات c# code. إظهار كافة الرسائل

c sharp : DATA STRUCTURES


DATA STRUCTURES

There are various ways of grouping sets of data together in C#.
Enumerations
An enumeration is a data type that enumerates a set of items by assigning to each of them an identifier (a name), while exposing an underlying base type for ordering the elements of the enumeration. The underlying type is int by default, but can be any one of the integral types except for char.
Enumerations are declared as follows:
enum Weekday { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
The elements in the above enumeration are then available as constants:
Weekday day = Weekday.Monday;
if (day == Weekday.Tuesday)
{
Console.WriteLine("Time sure flies by when you program in C#!");
}
If no explicit values are assigned to the enumerated items as the example above, the first element has the value 0, and the successive values are assigned to each subsequent element. However, specific values from the underlying integral type can be assigned to any of the enumerated elements:
enum Age { Infant = 0, Teenager = 13, Adult = 18 };
Age age = Age.Teenager;
Console.WriteLine("You become a teenager at an age of {0}.", (int)age);
The underlying values of enumerated elements may go unused when the purpose of an enumeration is simply to group a set of items together, e.g., to represent a nation, state, or geographical territory in a more meaningful way than an integer could. Rather than define a group of logically related constants, it is often more readable to use an enumeration.
It may be desirable to create an enumeration with a base type other than int. To do so, specify any integral type besides char as with base class extension syntax after the name of the enumeration, as follows:
enum CardSuit : byte { Hearts, Diamonds, Spades, Clubs };
Structs
Structures (keyword struct) are light-weight objects. They are mostly used when only a data container is required for a collection of value type variables.
24 | C# Programming Data Structures
Structs are similar to classes in that they can have constructors, methods, and even implement interfaces, but there are important differences. Structs are value types while classes are reference types, which means they behave differently when passed into methods as parameters. Another very important difference is that structs cannot support inheritance. While structs may appear to be limited with their use, they require less memory and can be less expensive if used in the proper way.
A struct can, for example, be declared like this:
struct Person
{
public string name;
public System.DateTime birthDate;
public int heightInCm;
public int weightInKg;
}
The Person struct can then be used like this:
Person dana = new Person();
dana.name = "Dana Developer";
dana.birthDate = new DateTime(1974, 7, 18);
dana.heightInCm = 178;
dana.weightInKg = 50;
if (dana.birthDate < DateTime.Now)
{
Console.WriteLine("Thank goodness! Dana Developer isn't from the future!");
}
It is also possible to provide constructors to structs to make it easier to initialize them:
using System;
struct Person
{
string name;
DateTime birthDate;
int heightInCm;
int weightInKg;
public Person(string name, DateTime birthDate, int heightInCm, int weightInKg)
{
this.name = name;
this.birthDate = birthDate;
this.heightInCm = heightInCm;
this.weightInKg = weightInKg;
}
}
public class StructWikiBookSample
{
public static void Main()
{
Person dana = new Person("Dana Developer", new DateTime(1974, 7, 18), 178, 50);
}
}

c# Sharp How can I disable the ALT+F4 method of closing the application

frist way

private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
{ 
    e.
Cancel = true; 
} 

second way
You can handle "Alt+F4" KeyDown to disable it.

1. set "KeyPreview" of your form to "true"

2. add "KeyDown" handler for your form (or override "OnKeyDown" method)

private void Form1_KeyDown(object sender
, System.Windows.Forms.KeyEventArgs e) {
if( e.Alt && e.KeyCode==Keys.F4 ) {
e.Handled=true;
}
}

c # : Number OnlyTextbox


First
      - add two textbox ( txtType1, txtType2 )
      - add three label ( label1, label2, label3 )
Second
      - Right click on textType1 and choose properties
      - move to Events and double click on  KeyPress
Third
      - add this code

//Using 2.0 Framework function TryParse


int isNumber = 0;
int.TryParse(e.KeyChar.ToString(), out isNumber);
if (isNumber == 0)
e.Handled = true;


Second
      - Right click on textType2 and choose properties

      - move to Events and double click on KeyPress
Third
      - add this code

//Using Regular Expressions
if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "\\d+"))
e.Handled = true;




C# Numbers Only in Textbox

I created a text box event handler to only allow my textbox to accept Numbers only. The Event handler works great and does not allow anything but numbers except when the form first loads and the character entered is non-numeric it then allows the first charcter to be entered can be non-numberic. If I enter a number then erase it it will not allow a non-numeric character.

I saw one example of this but the texbox had a underline in it but it did not have any code in it.
Here is my event handler right now
 
first way
C# Syntax
 
private void text1_TextChanged(object sender, EventArgs e)
{
      text1.KeyPress += new KeyPressEventHandler(rtbQuantity_KeyPress);
}
private void text1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < '0')  || (e.KeyChar > '9')) e.Handled = true;
}
 
 
sec way
 
private void txtType1_KeyPress(object sender, KeyPressEventArgs e)

{

int isNumber = 0; e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber);

}
 
 
3rt way
 
private void txtType1_KeyPress(object sender, KeyPressEventArgs e)


{

int isNumber = 0; e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber);

}

c#: Play wav files



// Play wav files

 System.Media.SoundPlayer player = new SoundPlayer();
 player.SoundLocation = "c:\\test.wav";
 player.LoadAsync();
 player.PlayLooping();   //asynchronous (loop)playing in new thread
 Thread.Sleep(5000);
 player.Stop();




c sharp Set image opacity

here you can set and change image opacity and more

public static Image SetOpacity(Image original, float opacity)
{
Bitmap temp = new Bitmap(original.Width, original.Height);
Graphics g = Graphics.FromImage(temp);
ColorMatrix cm = new ColorMatrix();
cm.Matrix33 = opacity;
ImageAttributes ia = new ImageAttributes();
ia.SetColorMatrix(cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.DrawImage(original, new Rectangle(0, 0, temp.Width, temp.Height), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, ia);
g.Dispose();
return temp;
}

with my best----> mohamed basha
c sharp Set image opacity, c #, code 2 all, java script, c sharp

How to call other applications using the

Windows Forms Controls: How to call other applications using the
Process control
this video description How to call other applications using the Process control

Named and Optional Parameters in C# 4.0

microsoft video
learning c charp
this video to description Named and Optional Parameters in C# 4.0
you can download this video click here

C # sharp: login dialogbox



 source code to create a login box
you can download source from here

c sharp in detail

free book for c# lang
you can download this from here
boook create by mr: jon jagger

C # sharp : Arrays


Arrays, Collections & String Manipulation
Lesson Plan
Today we will explore arrays, collections and string manipulation in C#. First of all, we will explore
multidimensional rectangular and jagged arrays. We will also explore how foreach iterates through a collection.
Then we will move to collections and see how they are implemented in C#. Later, we will explore different
collections like ArrayLists, Stacks, Queues and Dictionaries. Finally, we will see how strings are manipulated in
C#. We will explore both the string and the StringBuilder types.
Arrays Revisited
As we have seen earlier, an array is a sequential collection of elements of a similar data type. In C#, an array is an
object and thus a reference type, and therefore they are stored on the heap. We have only covered single dimension
arrays in the previous lessons, now we will explore multidimensional arrays.
Multidimensional Arrays
A multidimensional array is an 'array of arrays'. A multidimensional array is the one in which each element of the
array is an array itself. It is similar to tables in a database where each primary element (row) is a collection of
secondary elements (columns). If the secondary elements do not contain a collection of other elements, it is called
a 2-dimensional array (the most common type of multidimensional array), otherwise it is called an n-dimensional
array where n is the depth of the chain of arrays. There are two types of multidimensional arrays in C#:
•  Rectangular array (one in which each row contains an equal number of columns)
•  Jagged array (one in which each row does not necessarily contain an equal number of columns)
The images below show what the different kinds of arrays look like. The figure also shows the indexes of different
elements of the arrays. Remember, the first element of an array is always zero (0).



REFERENCES:C# School book - 
programmersheaven




C SHARP -


This code snippet will show you on how to create a simple xml file in Visual Studio 10 Beta 2.

Step 1: Add a namespace to your code behind System.Xml and System.Text
Step 2: In your event/method to create an xml file
//Create a path were to save the xml file
String path = Server.MapPath(@”FolderName\MyFileName.xml”);
//Instantiate an XmlWriterSettings
var xmlWrite = new XmlWriterSettings();
//And other Declaration
xmlWrite.Indent = true;
xmlWrite.OmitXmlDeclaration = true;
xmlWrite.Encoding = Encoding.ASCII;
//Then try to write a data in xml file
Using (var write = XmlWriter.Create(path,xmlWrite))
{
write.WriteComment(“This is a basic sample on how to create xml file”);
write.WriteStartElement(“Head”);
write.WriteStartElement(“Header”);
write.WriteStartAttribute(“Header”);
write.WriteValue(HeaderValue);
write.WriteEndAttribute();
write.WriteEndElement();
write.WriteStartElement(“Footer”);
write.WriteStartAttribute(“Footer”);
write.WriteValue(FooterValue);
write.WriteEndAttribute();
write.WriteEndElement();
write.Flush();
}
That’s it. This sample created on asp.net project.

C SHARP & V.B - How to Pass values to another Form

How to Pass values to another Form

Ok. Lets say you have 2 Forms. Form1 and Form2.

In Visual Basic 6 this is simple codes with 1 line only: Form2.text1.text = Form1.text1.text
Thats so Simple.
But in C# not 1 line code. I have 2 ways to get a text from Form1/Form2.

FIRST WAY:
1.) Goto Form1 then Double Click it. At the code type this.

public string CaptionText
{get {return textBox1.Text;}
set { textBox1.Text = value; }}
note: the value of your textbox1.text = sayre;
2.) Goto Form2 then Double click it. At the code type this.
// At your command button In Form2
private void button1_Click(object sender, EventArgs e)
{
Form1 sForm1 = new Form1();
textBox1.Text = sForm1.CaptionText;

}

SECOND WAY:

1.) Goto Form2 then Double click it. At the code type this.

public Form2(string sTEXT)
{
InitializeComponent();
textBox1.Text = sTEXT;
}
2.) Goto Form1 then Double click it. At the code type this.
//At your command button in Form1
private void button1_Click(object sender, EventArgs e)
{
Form2 sForm = new Form2(textBox1.Text);
sForm.Show();
}

c sharp - How to Get Date and Time Difference in C SHARP

I have example here on how to get the difference of date and time in C#.
Step: 1
Create a timer then set the interval to 10 and enabled to true.
Step: 2
Create 3 Label. Label1,Label2,Label3.
Step: 3
Create 2 Datepicker. Name it dtfrom and dtto.
Step: 4
Create a Button1
Then Copy this Code at your form:
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{label1.Text = dtfrom.Value.ToString();}
private void timer1_Tick(object sender, EventArgs e)
{label2.Text = string.Format("{0:G}", DateTime.Now);}
private void button1_Click(object sender, EventArgs e)
{
TimeSpan ts = new TimeSpan();
DateTime dt1,dt2 = new DateTime();
dt1 = dtfrom.Value;
dt2 = Convert.ToDateTime(label2.Text);
ts=dt1.Subtract(dt2);
label3.Text = ts.ToString(); //Answer
}

Share/Bookmark


                                                  WITH MY BEST: MOHAMED BASHA

C SHARP-Showing newest posts with label Progress Bar


In this code show you on how to use the progress bar with Insert command.

First Step:
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "your connectionstring";
conn.Open();
int i;
int x = 1000; //insert 1000 rows
Bar.Maximum = x; //Bar ( Your progressbar)
for (i = 0; i < x; i++)
{
string sQL = "Insert Into table1" & _ "(empid,dates,username) values ('COLLADO','11/4/1982','Sayre')";
OleDbCommand cmd = new OleDbCommand(sQL, conn);
cmd.ExecuteNonQuery();
Bar.Value = Bar.Value + 1;
pr = Bar.Value;
pr1 = pr / x;
pr2 = pr1 * 100;
lblpercent.Text = pr2.ToString(); //show the percent in label
Application.DoEvents();
}
//Get the total row in the table
string sQL1 = "select * from table1";
OleDbCommand cmd1 = new OleDbCommand(sQL1, conn);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd1);
da.Fill(ds);
string ss = ds.Tables[0].Rows.Count.ToString();

                    WITM MY BEST: MOHAMED BASHA

c# : Console Application - Get list of running processes

Get list of running processes
it's a console application

code
static void Main(string[] args)
{
Console.WriteLine("ID:\tProcess name:");
Console.WriteLine("--\t------------");
foreach (System.Diagnostics.Process process in System.Diagnostics.Process.GetProcesses())
Console.WriteLine("{0}\t{1}", process.Id, process.ProcessName);
Console.Read();
}

c# - Image Processing

this is source code to "Image Processing"  to edit image

                                     download here

Beginning Visual C# 2010

this is agreat book about  Beginning Visual C# 2010
download here

c# code || to make a password form

After drag and drop "group box" , "2 button" , "2 text box" and "2 label"
It was organized as the image


we will write this code in button"enter " then run

if (textBox1.Text == "mohamed" && textBox2.Text == "1")
{
form2 airline=new form2();
airline.show();
this.hide();
}
else if (textBox1.Text != "mohamed" && textBox2.Text != "1")
{
MessageBox.Show("enter true name or password", "error");
}

// with my best: mohamed basha





this code for basic date

<div style="color:#FF0000;font-size:16px;font-family:Arial;font-weight:bold;font-style:normal;text-decoration:underline" id="basicdate"></div>

<script type="text/javascript">

var now = new Date();

var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

var date = ((now.getDate() < 10) ? "0" : "") + now.getDate();

var year = (now.getYear() < 1000) ? now.getYear() + 1900 : now.getYear();

today = days[now.getDay()] + ", " + months[now.getMonth()] + " " + date + ", " + year;

var basicdate = document.getElementById('basicdate');

basicdate.innerHTML = today;

</script>






                                                     mohamed basha

Link With in

Related Posts Plugin for WordPress, Blogger...