Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - contenuto dll in una tabPage?
Forum - C# / VB.NET - contenuto dll in una tabPage? - Pagina 2

Pagine: [ 1 2 3 ] Precedente | Prossimo
Avatar
()
Newbie


Messaggi:
Iscritto:

Segnala al moderatore
Postato alle 18:56
Martedì, 30/06/2009
Testo quotato

Postato originariamente da Linkinf22:
:ot: Perchè? Cos' ho fatto di sbagliato che non è permesso dal regolamento?


[OT]
Si riferiva a questo, leggi:
http://www.pierotofy.it/pages/extras/forum/16/53085-estens ...
[/OT]

PM Quote
Avatar
Linkinf22 (Normal User)
Rookie


Messaggi: 59
Iscritto: 28/06/2009

Segnala al moderatore
Postato alle 12:35
Mercoledì, 01/07/2009
:ot: Ok, Scusatemi... la prossima volta cercherò di ricordarmene. Chiuso OT

Comunque, il programma lo vorrei fare senza scrivere nessun codice nel programma ma solo nella dll, cioè, mettiamo che io abbia messo un OpenFileDialog che mi permetta di aprire un file dll, io seleziono il file dll che voglio aprire e il contenuto della dll viene aggiunto al TabControl... si potrebbe fare?

PM Quote
Avatar
()
Newbie


Messaggi:
Iscritto:

Segnala al moderatore
Postato alle 13:10
Mercoledì, 01/07/2009
Allora cambia tutto :D tu stai dicendo che vuoi caricare una Dll a Runtime ed aggiungerne le proprietà al tuo TabControl giusto? Se è così, forse c'è qualche metodo del Namespace System.Reflection che può aiutarti! Ammesso che sia possibile :k:
P.S. Se vuoi esempi su come utilizzare i metodi del Namespace System.Reflection, scarica il programma DataViewer di Totem dalla sezione sorgenti VB.Net e convertilo in C# :)

PM Quote
Avatar
Linkinf22 (Normal User)
Rookie


Messaggi: 59
Iscritto: 28/06/2009

Segnala al moderatore
Postato alle 13:39
Mercoledì, 01/07/2009
Ok, ci sono riuscito, ho aggiunto l' eseguibile del programma nei riferimenti della dll e ho messo il modifier del tabControl su public, ora però non so come far eseguire la dll quando ho selezionato la dll e premuto Ok sull' openFileDialog. Sapete cosa devo scrivere nel private void openFileDialog_FileOk(object sender, CancelEventArgs e)?

PM Quote
Avatar
Il Totem (Admin)
Guru^2


Messaggi: 3635
Iscritto: 24/01/2006

Segnala al moderatore
Postato alle 13:48
Mercoledì, 01/07/2009
Evidentemente non hai neanche letto il codice che ti avevo suggerito io, che faceva proprio al caso tuo. Non è necessario aggiungere l'eseguibile nei riferimento della dll, poiché una tabcontrol è sempre un tabcontrol sia che sia nella libreria sia che venga dichiarato in un form: l'unico namespace che devi usare è system.windows.forms (che contiene la classe del controllo). Nella dll basta scrivere il metodo nella forma da me proposta precedentemente, ossia:
Codice sorgente - presumibilmente C# / VB.NET

  1. void Aggiungi(TabControl tab)
  2. {
  3.   //...
  4.   tab.TabPages.Add(pagina);
  5. ]


E per caricare il metodo basta usare la reflection:
Codice sorgente - presumibilmente C# / VB.NET

  1. Reflection.Assembly Asm = Reflection.Assembly.Load(dllPath);
  2. Type T = Asm.GetType("NomeClasse");
  3. Reflection.MethodInfo Method = T.GetMethod("Aggiungi");
  4. object Instance = Asm.CreateInstance(T.Name);
  5. Method.Invoke(Instance, new object[] { TabControl1 });


PM Quote
Avatar
Linkinf22 (Normal User)
Rookie


Messaggi: 59
Iscritto: 28/06/2009

Segnala al moderatore
Postato alle 20:52
Giovedì, 02/07/2009
Scusa Il Totem, ma ho provato a fare come dici tu, però quando seleziono il file .dll dall' openFileDialog e lo apro non succede niente, non si chiude nemmeno l' openFileDialog... ??? :grr: :d

PM Quote
Avatar
Il Totem (Admin)
Guru^2


Messaggi: 3635
Iscritto: 24/01/2006

Segnala al moderatore
Postato alle 13:29
Venerdì, 03/07/2009
Dato che non hai postato il codice, non posso che supporre che tu abbia sbagliato qualcosa. Per sapere cosa dovrei avere qualche informazione i più.

PM Quote
Avatar
Linkinf22 (Normal User)
Rookie


Messaggi: 59
Iscritto: 28/06/2009

Segnala al moderatore
Postato alle 15:43
Venerdì, 03/07/2009
Codice sorgente nell' applicazione

private void openFileDialog_FileOk(object sender, CancelEventArgs e)
{
    string dllPath = openFileDialog.FileName;
    Assembly AggiungiProgramma = Assembly.Load(dllPath);
    Type ClasseDelProgrammaDaAggiungere = AggiungiProgramma.GetType"ClasseDelProgramma");
    MethodInfo InformazioniMetodo = ClasseDelProgrammaDaAggiungere.GetMethod("AggiungiIlProgramma");
    Object Instanza = AggiungiProgramma.CreateInstance(ClasseDelProgrammaDaAggiungere.Name);
    InformazioniMetodo.Invoke(Instanza, new Object[] {tabunearth});
}

Codice sorgente della dll... Un po' lunghino

namespace Browser
{
    public class ClasseDelProgramma
    {
        unearth.FrmPrincipale FormPrincipaleUnearth = new FrmPrincipale();

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmPrincipale));
            this.tabBrowser = new System.Windows.Forms.TabPage();
            this.tabPagineWebBrowser = new System.Windows.Forms.TabControl();
            this.schedaBrowser = new System.Windows.Forms.TabPage();
            this.webBrowser = new System.Windows.Forms.WebBrowser();
            this.toolStripBrowser = new System.Windows.Forms.ToolStrip();
            this.tsbBrowserIndietro = new System.Windows.Forms.ToolStripButton();
            this.tsbBrowserAvanti = new System.Windows.Forms.ToolStripButton();
            this.tsbBrowserAddTab = new System.Windows.Forms.ToolStripButton();
            this.tsbBrowserRemoveTab = new System.Windows.Forms.ToolStripButton();
            this.tsbHome = new System.Windows.Forms.ToolStripButton();
            this.tsbImpostazioniBrowser = new System.Windows.Forms.ToolStripButton();
            this.btnBrowserVai = new System.Windows.Forms.Button();
            this.tbxBrowser = new System.Windows.Forms.TextBox();
            this.lblBrowser = new System.Windows.Forms.Label();
            this.browserToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.tabBrowser.SuspendLayout();
            this.tabPagineWebBrowser.SuspendLayout();
            this.schedaBrowser.SuspendLayout();
            this.toolStripBrowser.SuspendLayout();
            //
            // tabBrowser
            //
            this.tabBrowser.BackColor = System.Drawing.Color.CornflowerBlue;
            this.tabBrowser.Controls.Add(this.tabPagineWebBrowser);
            this.tabBrowser.Controls.Add(this.toolStripBrowser);
            this.tabBrowser.Controls.Add(this.btnBrowserVai);
            this.tabBrowser.Controls.Add(this.tbxBrowser);
            this.tabBrowser.Controls.Add(this.lblBrowser);
            this.tabBrowser.Location = new System.Drawing.Point(4, 22);
            this.tabBrowser.Name = "tabBrowser";
            this.tabBrowser.Padding = new System.Windows.Forms.Padding(3);
            this.tabBrowser.Size = new System.Drawing.Size(768, 521);
            this.tabBrowser.TabIndex = 0;
            this.tabBrowser.Text = "Browser";
            //
            // tabPagineWebBrowser
            //
            this.tabPagineWebBrowser.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.tabPagineWebBrowser.Controls.Add(this.schedaBrowser);
            this.tabPagineWebBrowser.Location = new System.Drawing.Point(0, 63);
            this.tabPagineWebBrowser.Name = "tabPagineWebBrowser";
            this.tabPagineWebBrowser.SelectedIndex = 0;
            this.tabPagineWebBrowser.Size = new System.Drawing.Size(772, 462);
            this.tabPagineWebBrowser.TabIndex = 5;
            //
            // schedaBrowser
            //
            this.schedaBrowser.Controls.Add(this.webBrowser);
            this.schedaBrowser.Location = new System.Drawing.Point(4, 22);
            this.schedaBrowser.Name = "schedaBrowser";
            this.schedaBrowser.Padding = new System.Windows.Forms.Padding(3);
            this.schedaBrowser.Size = new System.Drawing.Size(764, 436);
            this.schedaBrowser.TabIndex = 0;
            this.schedaBrowser.Text = "Scheda vuota";
            this.schedaBrowser.UseVisualStyleBackColor = true;
            //
            // webBrowser
            //
            this.webBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
            this.webBrowser.Location = new System.Drawing.Point(3, 3);
            this.webBrowser.MinimumSize = new System.Drawing.Size(20, 20);
            this.webBrowser.Name = "webBrowser";
            this.webBrowser.Size = new System.Drawing.Size(758, 430);
            this.webBrowser.TabIndex = 0;
            this.webBrowser.Url = new System.Uri("http://www.google.it", System.UriKind.Absolute);
            //
            // toolStripBrowser
            //
            this.toolStripBrowser.BackColor = System.Drawing.Color.CornflowerBlue;
            this.toolStripBrowser.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
            this.toolStripBrowser.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.tsbBrowserIndietro,
            this.tsbBrowserAvanti,
            this.tsbBrowserAddTab,
            this.tsbBrowserRemoveTab,
            this.tsbHome,
            this.tsbImpostazioniBrowser});
            this.toolStripBrowser.Location = new System.Drawing.Point(3, 3);
            this.toolStripBrowser.Name = "toolStripBrowser";
            this.toolStripBrowser.Size = new System.Drawing.Size(762, 25);
            this.toolStripBrowser.TabIndex = 4;
            this.toolStripBrowser.Text = "toolStrip1";
            //
            // tsbBrowserIndietro
            //
            this.tsbBrowserIndietro.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.tsbBrowserIndietro.ImageTransparentColor = System.Drawing.Color.White;
            this.tsbBrowserIndietro.Name = "tsbBrowserIndietro";
            this.tsbBrowserIndietro.Size = new System.Drawing.Size(23, 22);
            this.tsbBrowserIndietro.Text = "Indietro";
            //
            // tsbBrowserAvanti
            //
            this.tsbBrowserAvanti.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.tsbBrowserAvanti.ImageTransparentColor = System.Drawing.Color.White;
            this.tsbBrowserAvanti.Name = "tsbBrowserAvanti";
            this.tsbBrowserAvanti.Size = new System.Drawing.Size(23, 22);
            this.tsbBrowserAvanti.Text = "Avanti";
            //
            // tsbBrowserAddTab
            //
            this.tsbBrowserAddTab.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.tsbBrowserAddTab.Image = ((System.Drawing.Image)(resources.GetObject("tsbBrowserAddTab.Image")));
            this.tsbBrowserAddTab.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tsbBrowserAddTab.Name = "tsbBrowserAddTab";
            this.tsbBrowserAddTab.Size = new System.Drawing.Size(23, 22);
            this.tsbBrowserAddTab.Text = "+";
            //
            // tsbBrowserRemoveTab
            //
            this.tsbBrowserRemoveTab.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.tsbBrowserRemoveTab.Image = ((System.Drawing.Image)(resources.GetObject("tsbBrowserRemoveTab.Image")));
            this.tsbBrowserRemoveTab.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tsbBrowserRemoveTab.Name = "tsbBrowserRemoveTab";
            this.tsbBrowserRemoveTab.Size = new System.Drawing.Size(23, 22);
            this.tsbBrowserRemoveTab.Text = "-";
            //
            // tsbHome
            //
            this.tsbHome.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.tsbHome.Image = ((System.Drawing.Image)(resources.GetObject("tsbHome.Image")));
            this.tsbHome.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tsbHome.Name = "tsbHome";
            this.tsbHome.Size = new System.Drawing.Size(44, 22);
            this.tsbHome.Text = "Home";
            //
            // tsbImpostazioniBrowser
            //
            this.tsbImpostazioniBrowser.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.tsbImpostazioniBrowser.Image = ((System.Drawing.Image)(resources.GetObject("tsbImpostazioniBrowser.Image")));
            this.tsbImpostazioniBrowser.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tsbImpostazioniBrowser.Name = "tsbImpostazioniBrowser";
            this.tsbImpostazioniBrowser.Size = new System.Drawing.Size(79, 22);
            this.tsbImpostazioniBrowser.Text = "Impostazioni";
            //
            // btnBrowserVai
            //
            this.btnBrowserVai.Location = new System.Drawing.Point(287, 34);
            this.btnBrowserVai.Name = "btnBrowserVai";
            this.btnBrowserVai.Size = new System.Drawing.Size(40, 23);
            this.btnBrowserVai.TabIndex = 3;
            this.btnBrowserVai.Text = "Vai";
            this.btnBrowserVai.UseVisualStyleBackColor = true;
            //
            // tbxBrowser
            //
            this.tbxBrowser.Location = new System.Drawing.Point(55, 34);
            this.tbxBrowser.Name = "tbxBrowser";
            this.tbxBrowser.Size = new System.Drawing.Size(226, 20);
            this.tbxBrowser.TabIndex = 2;
            //
            // lblBrowser
            //
            this.lblBrowser.AutoSize = true;
            this.lblBrowser.BackColor = System.Drawing.Color.Transparent;
            this.lblBrowser.Location = new System.Drawing.Point(1, 37);
            this.lblBrowser.Name = "lblBrowser";
            this.lblBrowser.Size = new System.Drawing.Size(48, 13);
            this.lblBrowser.TabIndex = 1;
            this.lblBrowser.Text = "Indirizzo:";
        }

        private void AggiungiIlProgramma(TabControl tabunearth)
        {
            FormPrincipaleUnearth.tabunearth.TabPages.Add(tabBrowser);
        }

        private System.Windows.Forms.TabPage tabBrowser;
        private System.Windows.Forms.Label lblBrowser;
        private System.Windows.Forms.Button btnBrowserVai;
        private System.Windows.Forms.TextBox tbxBrowser;
        private System.Windows.Forms.ToolStrip toolStripBrowser;
        private System.Windows.Forms.TabControl tabPagineWebBrowser;
        private System.Windows.Forms.TabPage schedaBrowser;
        public System.Windows.Forms.WebBrowser webBrowser;
        private System.Windows.Forms.ToolStripButton tsbHome;
        private System.Windows.Forms.ToolStripButton tsbBrowserIndietro;
        private System.Windows.Forms.ToolStripButton tsbBrowserAvanti;
        private System.Windows.Forms.ToolStripButton tsbBrowserAddTab;
        private System.Windows.Forms.ToolStripButton tsbImpostazioniBrowser;
        private System.Windows.Forms.ToolStripButton tsbBrowserRemoveTab;
        private System.Windows.Forms.ToolStripMenuItem browserToolStripMenuItem;
    }
}

PM Quote
Pagine: [ 1 2 3 ] Precedente | Prossimo