Armenian Knowledge Base  

Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters
Register

Reply
 
LinkBack Thread Tools
Old 17.07.2007, 19:14   #1
Академик
 
Join Date: 01 2002
Location: Shambala
Age: 38
Posts: 7,015
Downloads: 11
Uploads: 0
Reputation: 267 | 5
Default C# ic harc

Zoxovurd uxexs cakvav mi ban sxal em anum ha errora tali

uremn xndirs dasakana

ka MDI application.

MainForm u mek el ChildForm

uzum em ChildForm pakveluc xabar ani MaiNForm in vor pakvela

Dra hamar delegat,event u argument er em haytararum ChildForm i class um senc

publicclassUserRequestEventArgs : EventArgs
{
publicstring Message;
public UserRequestEventArgs(string s)
{
Message = s;
}
}
publicdelegatevoidUserRequest(object sender, UserRequestEventArgs e);
publiceventEventHandler<UserRequestEventArgs> OnUserRequest;


heto ed nuyn CHildForm i classum grum em vor pakveluc

...
if (OnUserRequest != null)
{
UserRequestEventArgs mtcea =
newUserRequestEventArgs("Message from OnOneSecond");
erRequest(sender, mtcea);
}
this.Close();
...

u mek el MAIN FORM i classum

frm.OnUserRequest += newfrmMain.UserRequest();


u mek el asum em ed nuyn MAINFROM um vor

privatevoid UserReq(object sender, UserRequestEventArgs e)
{
MessageBox.Show( e.Message.ToString());
}

vortex frm ed childform i arden stexcac instance a, isk frmMain el MAIN FORMNA

inchna ste sxal zoxovurd???

compile chi linum

xndrum em es xndir asxhatacneq motnerd henc stacvi (henc CHILD formen pakes main forum MessageBox.SHow lini) aseq grem tesnem.
__________________
Ախպեր դու էմիգրացիան տուրիզմի հետ մի խառնի...

http://moskull.livejournal.com/
Reply With Quote
Old 18.07.2007, 16:55   #2
Академик
 
Join Date: 01 2002
Location: Shambala
Age: 38
Posts: 7,015
Downloads: 11
Uploads: 0
Reputation: 267 | 5
Default

ste C# imacox chka vor uzena indz ogni ?
Reply With Quote
Old 02.08.2007, 18:21   #3
Creator
 
Join Date: 06 2002
Location: Sliema, Malta
Age: 39
Posts: 28
Downloads: 1
Uploads: 0
Reputation: 12 | 0
Default

I think in MainForm you should add your event hadler in this way:

frm.OnUserRequest += new UserRequest(frmMain.UserReq);
Reply With Quote
Old 03.08.2007, 08:23   #4
Грустно...
 
Agregat's Avatar
 
Join Date: 08 2002
Location: Там, где всегда идут дожди
Age: 35
Posts: 21,717
Downloads: 2
Uploads: 0
Reputation: 250 | 7
Default

Quote:
Originally Posted by Michellangelo
frm.OnUserRequest += new UserRequest(frmMain.UserReq);
или если .NET2.0 или старше просто += frmMain.UserReq.

Но проблема тут в дизайне и не совсем ясно, как будешь потом отписываться от евента, ведь дочерняя форма-то уже может быть диспознутой. Так можно и мемори ликов нахвататься.
Reply With Quote
Old 03.08.2007, 14:54   #5
Академик
 
Join Date: 01 2002
Location: Shambala
Age: 38
Posts: 7,015
Downloads: 11
Uploads: 0
Reputation: 267 | 5
Default

zzvum em es anasun C sharp ic C++ ov u Windows messaging ov hastat aveli hamar er, ste dllimport ban man eeheeee
Reply With Quote
Old 03.08.2007, 15:09   #6
Грустно...
 
Agregat's Avatar
 
Join Date: 08 2002
Location: Там, где всегда идут дожди
Age: 35
Posts: 21,717
Downloads: 2
Uploads: 0
Reputation: 250 | 7
Default

Уфффф....
Reply With Quote
Old 17.08.2007, 13:53   #7
Академик
 
TigrOm's Avatar
 
Join Date: 06 2004
Location: Yerevan
Posts: 9,326
Downloads: 3
Uploads: 0
Reputation: 680 | 5
Default

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

namespace WindowsApplication1
{
    public partial class ChildForm : Form
    {
        public ChildForm()
        {
            InitializeComponent();
        }
    }
}
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class MDIForm : Form
    {

        ChildForm chilForm = new ChildForm();
        public MDIForm()
        {
            InitializeComponent();
            chilForm.Show(this);
            chilForm.FormClosed += new FormClosedEventHandler(OnFormClosed);
        }

        private void OnFormClosed(object sender, FormClosedEventArgs e)
        {
            MessageBox.Show(e.CloseReason.ToString());
        }
    }
}
Но ИМХО есть технологии которые избавят от написания такого кода. Smart Client Software Factory (CAB) и подобные...
Reply With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 01:19.


Powered by vBulletin® Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.