PDA

View Full Version : سوال: نحوه خروجی گرفتن کامپوننت های سی شارپ؟؟؟



md3848
یک شنبه 11 مرداد 1394, 18:24 عصر
سلام
چطور میشه یه کامپوننت رو از یه سیستم به صورت فایل dll در ابرد و در سیستم دیگه ای ازش استفاده کرد؟؟؟:متفکر:

davidrobert
یک شنبه 11 مرداد 1394, 19:43 عصر
شما برای اینکه بتونید کامپوننت dll بسازید باید قسمت ایجاد پروزه جدید روی
133853
کلیک کنید و در فرم مورد نظر .
UserControl1.cs رو پاک کنید و یک کلاس جدید باز کنید و برای ساخ کامپوننت داخل کلاس . به این صورت کد نویسی کنید.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;

namespace TxtMulti
{
public class TxtMulti : TextBoxX
{
private Color bk;
private Color bkfocus;
private type typetextbox;

public TxtMulti()
{
this.bk = base.BackColor;
base.TextChanged += new EventHandler(this.ExtdTextBox_TextChanged);
base.KeyPress += new KeyPressEventHandler(this.ExtdTextBox_KeyPress);
base.LostFocus += new EventHandler(this.ExtdTextBox_LostFocus);
base.Enter += new EventHandler(this.ExtendTextBox_Enter);
base.KeyDown += new KeyEventHandler(this.TextBoxReza_KeyDown);
this.bkfocus = Color.FromArgb(0xcc, 0xff, 0xbd);
//strCrncySymbol = "ریال";
//strCrncyGrpSep = ",";
base.RightToLeft = RightToLeft.Yes;
}

private void changelanguge(string lname)
{
foreach (InputLanguage language in InputLanguage.InstalledInputLanguages)
{
if (language.Culture.TwoLetterISOLanguageName == lname)
{
Application.CurrentCulture = language.Culture;
Application.CurrentInputLanguage = language;
}
}
}

private void ExtdTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (this.typetextbox == type.floating)
{
if ((!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)) && (e.KeyChar != '.'))
{
e.Handled = true;
}
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
else if (this.typetextbox == type.numeric)
{
if (!(char.IsControl(e.KeyChar) || char.IsDigit(e.KeyChar)))
{
e.Handled = true;
}
}
else if (this.typetextbox == type.money)
{
if (!(char.IsControl(e.KeyChar) || char.IsDigit(e.KeyChar)))
{
e.Handled = true;
}
}
else if (((this.typetextbox != type.general) && (this.typetextbox == type.nonumeric)) && (char.IsDigit(e.KeyChar) || (e.KeyChar == '.')))
{
e.Handled = true;
}
}

private void ExtdTextBox_LostFocus(object sender, EventArgs e)
{
this.BackColor = this.bk;
base.Width -= 6;
base.Left += 3;
}

private void ExtdTextBox_TextChanged(object sender, EventArgs e)
{
if ((this.typetextbox == type.money) && (this.Text != ""))
{
this.Text = Convert.ToDecimal(this.Text).ToString("#,#", CultureInfo.InvariantCulture);
}
base.Select(this.Text.Length, 0);
}

private void ExtendTextBox_Enter(object sender, EventArgs e)
{
this.changelanguge("fa");
this.bk = base.BackColor;
this.BackColor = this.bkfocus;
base.Width += 6;
base.Left -= 3;
base.Select(0, this.Text.Length);
}

private void TextBoxReza_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
SendKeys.Send("{tab}");
}
}

[DisplayName("Type"), Category("Extended Properties"), Description("sets type TextBox"), Browsable(true)]
public type typetxt
{
get
{
return this.typetextbox;
}
set
{
this.typetextbox = value;
}
}

[Browsable(true), Category("Extended Properties"), Description("set Backcolor Focuse"), DisplayName("BackColorFocus")]
public Color WaterMarkBackColor
{
get
{
return this.bkfocus;
}
set
{
this.bkfocus = value;
base.OnTextChanged(new EventArgs());
}
}

public enum type
{
general,
nonumeric,
numeric,
money,
floating
}














//public override string Text
//{
// get
// {
// return base.Text;
// }
// set
// {
// base.Text = value;
// }
//}

//public override RightToLeft RightToLeft
//{
// get
// {
// return base.RightToLeft;
// }
// set
// {
// base.RightToLeft = value;
// }
//}

///// <summary>
///// CurrencySymbol for Money
///// default is "ریال"
///// </summary>
//private string strCrncySymbol;

//public string CurrencySymbol
//{
// get { return strCrncySymbol; }
// set { strCrncySymbol = value.Trim(); }
//}

///// <summary>
///// CurrencyGroupSeparator for Money
///// default is ","
///// </summary>
//private string strCrncyGrpSep;

//public string CurrencyGroupSeparator
//{
// get { return strCrncyGrpSep; }
// set { strCrncyGrpSep = value.Trim(); }
//}


///// <summary>
///// the value of TextBox that dosnt have "CurrencyGroupSeparator" and "CurrencySymbol"
///// to do calculation with it you should casting it
///// </summary>
//private static string strValue;

//public string value
//{
// get
// {
// return base.Text.Replace(strCrncyGrpSep, string.Empty).Replace(strCrncySymbol, string.Empty);
// }
//}

///// <summary>
///// Overrided method OnEnter that Select all text on TextBox when focus enter
///// </summary>
///// <param name="e"></param>
//protected override void OnEnter(EventArgs e)
//{
// base.SelectAll();
//}

///// <summary>
///// Overrided method Click that Select all text on TextBox when TextBox Clicked
///// </summary>
///// <param name="e"></param>
//protected override void OnClick(EventArgs e)
//{
// base.SelectAll();
//}
///// <summary>
///// Overrided method OnLeave that add "CurrencySymbol" and "CurrencyGroupSeparator" to text in TextBox
///// </summary>
///// <param name="e"></param>
//protected override void OnLeave(EventArgs e)
//{
// if (((base.Text.IndexOf(strCrncySymbol) == -1) & (base.Text.IndexOf(strCrncyGrpSep) == -1) & (!string.IsNullOrEmpty(base.Text))))
// {
// NumberFormatInfo nfi = new NumberFormatInfo();
// nfi.CurrencyDecimalDigits = 0;
// nfi.CurrencyGroupSeparator = strCrncyGrpSep;
// base.Text = Int64.Parse(base.Text, NumberStyles.AllowThousands).ToString("#" + strCrncyGrpSep + "#", nfi);
// base.Text = base.Text.Insert(base.Text.Length, strCrncySymbol);
// }
// else
// base.OnLeave(e);
//}

///// <summary>
///// Overrided method KeyPress that only allow user to enter Digit value and Control key
///// </summary>
///// <param name="e"></param>
//protected override void OnKeyPress(KeyPressEventArgs e)
//{
// e.Handled = (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar)) ? false : true;
//}











//public enum TextBoxMode
//{
// IntNumber,
// DecNumber,
// Text
//}

//private TextBoxMode mode = TextBoxMode.DecNumber;
//private bool digitGroup = true;
//private bool currency = true;
//private string currencySymbol = " ریال";

//private string simpleText = string.Empty;

///// <summary>
///// Get or set the mode of textbox.
///// </summary>
//[Category("Mode"), DefaultValue(TextBoxMode.DecNumber)]
//public TextBoxMode Mode
//{
// get
// {
// return mode;
// }
// set
// {
// mode = value;
// }
//}

///// <summary>
///// Get or set the value for show the ',' character when use the IntNumber or DesNumber modes.
///// </summary>
//[Category("Mode"), DefaultValue(true), Description("Show the ',' character in numerics mode.")]
//public bool DigitGroup
//{
// get
// {
// return digitGroup;
// }
// set
// {
// digitGroup = value;
// }
//}

///// <summary>
///// Get or set the value for show the Currency Symbol when use the IntNumber or DesNumber modes.
///// </summary>
//[Category("Mode"), DefaultValue(true), Description("Show the Currency Symbol in numerics mode.")]
//public bool Currency
//{
// get
// {
// return currency;
// }
// set
// {
// currency = value;
// }
//}

///// <summary>
///// Get or set the value for Currency Symbol when use the Currency.
///// </summary>
//[Category("Mode"), DefaultValue("ریال"), Description("Currency Symbol in numerics mode.")]
//public string CurrencySymbol
//{
// get
// {
// return currencySymbol.Trim();
// }
// set
// {
// currencySymbol = value.Trim().Insert(0, " ");
// }
//}

///// <summary>
///// Get the current text without the digit character.
///// </summary>
//public string SimpleText
//{
// get
// {
// return simpleText;
// }
// private set
// {
// if (mode == TextBoxMode.Text)
// simpleText = value;
// else
// {
// simpleText = value.Replace(",", string.Empty);
// if (simpleText.IndexOf(currencySymbol) > 0)
// {
// simpleText = simpleText.Replace(currencySymbol, String.Empty);
// }
// }
// }
//}

//protected override void OnKeyPress(KeyPressEventArgs e)
//{
// char key = e.KeyChar;

// switch (mode)
// {
// case TextBoxMode.IntNumber:
// if (this.SelectionStart == 0 && key == '0')
// e.Handled = true;
// if (!(char.IsDigit(key) || key == '\b'))
// e.Handled = true;
// break;
// case TextBoxMode.DecNumber:
// if (this.SelectionStart == 0 && key == '0')
// {
// this.Text = this.Text.Insert(0, "0.");
// e.Handled = true;
// ;
// }
// if (!(char.IsDigit(key) || key == '\b' || key == '.'))
// e.Handled = true;
// else if (key == '.' && simpleText.Contains("."))
// e.Handled = true;
// break;
// }

// base.OnKeyPress(e);
//}

//protected override void OnTextChanged(EventArgs e)
//{
// if (!DesignMode)
// {

// SimpleText = this.Text;
// string str = simpleText;

// // del strCrncySymbol = "ریال" if exist
// if (str.IndexOf(currencySymbol) > 0)
// {
// str = str.Replace(currencySymbol, String.Empty);
// }

// // del strCrncyGrpSep = "," if exist
// //if ( base.Text.IndexOf(strCrncyGrpSep) > 0 )
// //{
// // base.Text = base.Text.Replace(strCrncyGrpSep, String.Empty);
// //}


// switch (mode)
// {
// case TextBoxMode.IntNumber:

// #region , Handle
// if (digitGroup)
// for (int i = str.Length - 3; i > 0; i -= 3)
// str = str.Insert(i, ",");
// #endregion
// break;

// case TextBoxMode.DecNumber:

// #region 0. Handle
// if (str.StartsWith("0") && str.IndexOf('.') != 1)
// {
// str = str.Replace(".", string.Empty);
// str = str.Insert(1, ".");
// }
// if (str.IndexOf('.') == 0)
// str = str.Insert(0, "0");
// #endregion

// #region , Handle
// if (digitGroup)
// {
// if (str.Contains("."))
// for (int i = str.IndexOf('.') - 3; i > 0; i -= 3)
// str = str.Insert(i, ",");
// else
// for (int i = str.Length - 3; i > 0; i -= 3)
// str = str.Insert(i, ",");
// }
// #endregion
// break;
// }

// //add strCrncySymbol = "ریال" to value
// if (mode != TextBoxMode.Text)
// {
// if (currency)
// {
// str = str.Insert(str.Length, currencySymbol);
// }
// }


// this.Text = str;
// this.Select(this.Text.Length, 0);
// base.OnTextChanged(e);
// }
//}

//public override RightToLeft RightToLeft
//{
// get
// {
// return base.RightToLeft;
// }
// set
// {
// base.RightToLeft = value;
// }
//}

//protected override void OnEnter(EventArgs e)
//{
// base.SelectAll();
// base.OnEnter(e);
//}









//public enum TextBoxMode
//{ IntNumber, DecNumber, Text }

//private TextBoxMode mode = TextBoxMode.DecNumber;
//private bool digitGroup = true;
//private bool currency = true;
//private string currencySymbol = " ریال";

//private string simpleText = string.Empty;

//[Category("Mode"), DefaultValue(TextBoxMode.DecNumber)]
//public TextBoxMode Mode
//{
// get { return mode; }
// set { mode = value; }
//}

//[Category("Mode"), DefaultValue(true), Description("Show the ',' character in numerics mode.")]
//public bool DigitGroup
//{
// get { return digitGroup; }
// set { digitGroup = value; }
//}


//[Category("Mode"), DefaultValue(true), Description("Show the Currency Symbol in numerics mode.")]
//public bool Currency
//{
// get { return currency; }
// set { currency = value; }
//}


//[Category("Mode"), DefaultValue("ریال"), Description("Currency Symbol in numerics mode.")]
//public string CurrencySymbol
//{
// get
// {
// return currencySymbol.Trim();
// }
// set
// {
// currencySymbol = value.Trim().Insert(0, " ");
// }
//}

//public string SimpleText
//{
// get
// {
// return simpleText;
// }
// private set
// {
// if (mode == TextBoxMode.Text)
// simpleText = value;
// else
// {
// simpleText = value.Replace(",", string.Empty);
// if (simpleText.IndexOf(currencySymbol) > 0)
// {
// simpleText = simpleText.Replace(currencySymbol, String.Empty);
// }
// }
// }
//}

//protected override void OnKeyPress(KeyPressEventArgs e)
//{
// char key = e.KeyChar;

// switch (mode)
// {
// case TextBoxMode.IntNumber:
// if (this.SelectionStart == 0 && key == '0')
// e.Handled = true;
// if (!(char.IsDigit(key) || key == '\b'))
// e.Handled = true;
// break;
// case TextBoxMode.DecNumber:
// if (this.SelectionStart == 0 && key == '0')
// {
// this.Text = this.Text.Insert(0, "0.");
// e.Handled = true; ;
// }
// if (!(char.IsDigit(key) || key == '\b' || key == '.'))
// e.Handled = true;
// else if (key == '.' && simpleText.Contains("."))
// e.Handled = true;
// break;
// }

// base.OnKeyPress(e);
//}

//protected override void OnTextChanged(EventArgs e)
//{
// if (!DesignMode)
// {

// SimpleText = this.Text;
// string str = simpleText;

// // del strCrncySymbol = "ریال" if exist
// if (str.IndexOf(currencySymbol) > 0)
// {
// str = str.Replace(currencySymbol, String.Empty);
// }

// // del strCrncyGrpSep = "," if exist
// //if ( base.Text.IndexOf(strCrncyGrpSep) > 0 )
// //{
// // base.Text = base.Text.Replace(strCrncyGrpSep, String.Empty);
// //}


// switch (mode)
// {
// case TextBoxMode.IntNumber:

// #region , Handle
// if (digitGroup)
// for (int i = str.Length - 3; i > 0; i -= 3)
// str = str.Insert(i, ",");
// #endregion
// break;

// case TextBoxMode.DecNumber:

// #region 0. Handle
// if (str.StartsWith("0") && str.IndexOf('.') != 1)
// {
// str = str.Replace(".", string.Empty);
// str = str.Insert(1, ".");
// }
// if (str.IndexOf('.') == 0)
// str = str.Insert(0, "0");
// #endregion

// #region , Handle
// if (digitGroup)
// {
// if (str.Contains("."))
// for (int i = str.IndexOf('.') - 3; i > 0; i -= 3)
// str = str.Insert(i, ",");
// else
// for (int i = str.Length - 3; i > 0; i -= 3)
// str = str.Insert(i, ",");
// }
// #endregion
// break;
// }

// //add strCrncySymbol = "ریال" to value
// if (mode != TextBoxMode.Text)
// {
// if (currency)
// {
// str = str.Insert(str.Length, currencySymbol);
// }
// }


// this.Text = str;
// this.Select(this.Text.Length, 0);
// base.OnTextChanged(e);
// }
//}

//public override RightToLeft RightToLeft
//{
// get
// {
// return base.RightToLeft;
// }
// set
// {
// base.RightToLeft = value;
// }
//}

//protected override void OnEnter(EventArgs e)
//{
// base.SelectAll();
// base.OnEnter(e);
//}
}
}

وقتی به این صورت کد نویسی کردید داخل کلاس و ذخیره کردید از منو build روی build soultion کلیک کنید تا کامپوننت شما ساخته بشه و اون موقع کامپوننت مورد نیاز با امکانات خودتون به برناه میتونید اضافه کنید و ازش استفاده کنید.

md3848
یک شنبه 11 مرداد 1394, 20:07 عصر
ممنون داش
چطوری میشه کامپوننتی که از قبل موجود هستش رو فایل dll اش رو پیدا کرد و یا دریافت کرد؟

davidrobert
یک شنبه 11 مرداد 1394, 20:15 عصر
شما وقتی فایل کامپوننت مورد نظر رو امنتخاب میکنید و روی فرم قرار مید در اصل شما اون فایل رو ندارید برای اینکه اون رو به دست بیارید باید ببنید در قسمت refrence امده یا نه اگه اون کامپوننت در قسمت refrence بود روش کلید راست کنید تا قسمت ویژگی هاش باز بشه و قسمت local copy رو true کنید وقتی پروژه رو اجرا کنید در کنار فایل اجرایتون کامپوننت رو قرار میده.