صدازدن رویداد کلیک از button در فرم دیگر
سلام دوستان
من به این شکل یک button که در فرم دیگه ای هست صدا میزنم و می خوام که این دکمه در داخل یک فرم دیگه کلیک بشه
var form2 = new Form2();
f2.button1.PerformClick();
با اینکه خطا هم نمیده button1 که در فرم دیگه ای هست هم کلیک نمیشه و اون کدهایی که داخل این دکه هست اجرا نمیشه
دلیلش چیه؟:ناراحت:
نقل قول: صدازدن رویداد کلیک از button در فرم دیگر
سلام، منظورتون اینه که یه دکمه بر روی فرم دوم دارین و میخواین وقتی روش کلیک کردین کدهایی که تو رویداد کلیک دکمه موجود در فرم اول نوشتین اجرا بشن؟
بیشتر توضیح بدین یا کدهای موجود در هر دو فرم رو بذارین تا راهنماییتون کنم
نقل قول: صدازدن رویداد کلیک از button در فرم دیگر
نقل قول:
نوشته شده توسط
hsn_abieteh
سلام دوستان
من به این شکل یک button که در فرم دیگه ای هست صدا میزنم و می خوام که این دکمه در داخل یک فرم دیگه کلیک بشه
var form2 = new Form2();
f2.button1.PerformClick();
با اینکه خطا هم نمیده button1 که در فرم دیگه ای هست هم کلیک نمیشه و اون کدهایی که داخل این دکه هست اجرا نمیشه
دلیلش چیه؟:ناراحت:
روش منطقی نیست که شما کدی در دکمه ایی در فرم شماره یک بنویسی و در فرم شماره 2 فراخوانی کنی.موقعی که روی دکمه در فرم شماره دو ،کلیک کنی دو حالت وجود دارد 1- فرم شماره یک باز هست و بسته نشده و حالت دیگر آن فرم توسط کاربر بسته شده(کد های بالا مربوط به این حالت هست که شما نوشتی) در حالت اول شما بایدhandle فرم شماره یک رو بدست بیاری بعد متد کلیک آن رافراخوانی کنی یا راه دیگر میتونی متغییر فرم شماره یک رو به فرم شماره دو پاس کنی و از اون استفاده کنی.من این دو روش رو پیاده سازی رو پیشنهاد نمیدم.
شما کدهای داخل رویداد کلیک دکمه در فرم شماره یک رو در یک کلاس که بصورت سراسری در پروژه قابل دسترسی باشه تعریف کن و در هر فرمی که خواستی در رویداد کلیک دکمه آن تابع رو فراخوانی کن.
نقل قول: صدازدن رویداد کلیک از button در فرم دیگر
نقل قول:
نوشته شده توسط
csharp.net
سلام، منظورتون اینه که یه دکمه بر روی فرم دوم دارین و میخواین وقتی روش کلیک کردین کدهایی که تو رویداد کلیک دکمه موجود در فرم اول نوشتین اجرا بشن؟
بیشتر توضیح بدین یا کدهای موجود در هر دو فرم رو بذارین تا راهنماییتون کنم
اره دقیقا همین. دو تا فرم دارم و می خوام با کلیک بر روی button1 در فرم یک رویداد کلیک در button2 در فرم 2 فراخوانی بشه و کدهایی که در button2 دارم اجرا بشه
کمکم کنید لطفا
نقل قول: صدازدن رویداد کلیک از button در فرم دیگر
نقل قول:
نوشته شده توسط
ژیار رحیمی
روش منطقی نیست که شما کدی در دکمه ایی در فرم شماره یک بنویسی و در فرم شماره 2 فراخوانی کنی.موقعی که روی دکمه در فرم شماره دو ،کلیک کنی دو حالت وجود دارد 1- فرم شماره یک باز هست و بسته نشده و حالت دیگر آن فرم توسط کاربر بسته شده(کد های بالا مربوط به این حالت هست که شما نوشتی) در حالت اول شما بایدhandle فرم شماره یک رو بدست بیاری بعد متد کلیک آن رافراخوانی کنی یا راه دیگر میتونی متغییر فرم شماره یک رو به فرم شماره دو پاس کنی و از اون استفاده کنی.من این دو روش رو پیاده سازی رو پیشنهاد نمیدم.
شما کدهای داخل رویداد کلیک دکمه در فرم شماره یک رو در یک کلاس که بصورت سراسری در پروژه قابل دسترسی باشه تعریف کن و در هر فرمی که خواستی در رویداد کلیک دکمه آن تابع رو فراخوانی کن.
راستش من کلی گزارش برای برنامم در یک فرم با adoconnection- adocommand- stimolreport درست کردم و برای اجرای هر کدوم یک button اختصاص دادم ولی حالا بنده خدایی که کار رو براش کردم میگه من میخوام از فرم اصلی با یک کلیک به گزارش دلخواهم دسترسی داشته باشم و نمی خواد که فرم صفحه گزارش گیری دیگه باز بشه
حالا من برا سادگی کارم میخوام که هر کدوم از دکمه هام رو از فرم اصلی صدا بزنم و stimolreport مربوطه مستقیم اجرا بشه
من چون تازه C# رو شروع کردم به مشکل خوردم. لطفا کمک بفرمایید...
نقل قول: صدازدن رویداد کلیک از button در فرم دیگر
تابع شون کن، هرجا خواستی صداشون کن.
نقل قول: صدازدن رویداد کلیک از button در فرم دیگر
نقل قول:
نوشته شده توسط
hsn_abieteh
سلام دوستان
من به این شکل یک button که در فرم دیگه ای هست صدا میزنم و می خوام که این دکمه در داخل یک فرم دیگه کلیک بشه
var form2 = new Form2();
f2.button1.PerformClick();
با اینکه خطا هم نمیده button1 که در فرم دیگه ای هست هم کلیک نمیشه و اون کدهایی که داخل این دکه هست اجرا نمیشه
دلیلش چیه؟:ناراحت:
دوتاپیشنهاددارم:
یه روش اینکه عملیات مورد نظرت رو به شکل یه تابع استاتیک در هر کدوم از فرم هایی که دوست داری و یا در یه کلاس جداگانه اصلا بنویس و هرجا لازم داشتی فراخوانی کن.
روش دوم اینکه در فرمی که براش رویداد نوشتی یه پروپرتی پابلیک استاتیک تعریف کن و در قسمت set رویداد کلیکی از همین فرم رو که لازم داری صدا بزن
و در فرم دومت فقط اون پروپرتی فرم اول رو مقدار بده تا تابع کلیک مورد نظرت اجرا بشه (البته به شرطی که همزمان هر دو فرم در حال حیات باشن یعنی باز باشن)
1 ضمیمه
نقل قول: صدازدن رویداد کلیک از button در فرم دیگر
نقل قول:
نوشته شده توسط
hsn_abieteh
اره دقیقا همین. دو تا فرم دارم و می خوام با کلیک بر روی button1 در فرم یک رویداد کلیک در button2 در فرم 2 فراخوانی بشه و کدهایی که در button2 دارم اجرا بشه
کمکم کنید لطفا
دقیقا همینه
نقل قول: صدازدن رویداد کلیک از button در فرم دیگر
نقل قول:
نوشته شده توسط
golestan1
دقیقا همینه
سلام
ممنون جهت پاسختون، من تو یک پروژه هام در فرم اول وقتی روی یک باتن کلیک می کنم میخام بعد از نمایش فرم دوم، رویداد keydown یک textbox (در فرم دوم )را صدا بزنم ....
میشه راهنماییم کنید؟
نقل قول: صدازدن رویداد کلیک از button در فرم دیگر
من از این روش استفاده کردم
(Application.OpenForms["form1"].Controls["Button1"] as Button).PerformClick();
نقل قول: صدازدن رویداد کلیک از button در فرم دیگر
از این روش هم می تونید استفاده کنید :
var frm = Application.OpenForms.Cast<Form>().Where(x => x.Name == "frmUsers").FirstOrDefault();
if (null != frm)
{
frmUsers master = (frmUsers)Application.OpenForms["frmUsers"];
master.btnRefresh.PerformClick();
}