Question about multiple namespace

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Stevens

    Question about multiple namespace

    I am having a bit of a problem accessing some information in a different
    namespace,
    hopefully someone can point out what I am doing wrong.

    I have a dll file that I dont want to use in my program, I just want to use
    the functions
    in my program. But after placing the class into my program, I can't seem to
    get the
    funcs to compile.

    //------------------------------------------------------------------------------
    namespace TextBox_Editor
    {
    public partial class frmMain : Form
    {
    public frmMain()
    {
    InitializeCompo nent();
    }

    // I want to access 'Settings' from below here in the main
    // scope but the error states it does not kow what it is.
    private void frmMain_Load(ob ject sender, EventArgs e)
    {
    TextBox1.Settin gs.Keywords.Add ("function") ;
    }

    namespace Highlighter
    {
    public class MyTextBox : System.Windows. Forms.TextBox
    {
    private mySettings m_settings = new mySettings();
    private string strtrLine = "";

    public SyntaxSettings Settings
    {
    get { return m_settings; }
    }
    }
    }
    }
    }

    What do I need to do here to get this to work?


    TIA


  • Jon Skeet [C# MVP]

    #2
    Re: Question about multiple namespace

    Rob Stevens <robbstephens@s undry.comwrote:
    I am having a bit of a problem accessing some information in a different
    namespace, hopefully someone can point out what I am doing wrong.
    Well, you haven't shown where or how TextBox1 is declared. Is it
    declared to be a MyTextBox? Does that part work, barring access to
    Settings?

    --
    Jon Skeet - <skeet@pobox.co m>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    World class .NET training in the UK: http://iterativetraining.co.uk

    Comment

    • Ignacio Machin \( .NET/ C# MVP \)

      #3
      Re: Question about multiple namespace

      Hi,
      +

      --
      Ignacio Machin
      The #1 Warehouse Management System & Direct Store Delivery Software (DSD) for QuickBooks & ERP Systems – LaceUp Solutions

      Mobile & warehouse Solutions.
      "Rob Stevens" <robbstephens@s undry.comwrote in message
      news:uPGh653RIH A.4740@TK2MSFTN GP02.phx.gbl...
      >I am having a bit of a problem accessing some information in a different
      >namespace,
      hopefully someone can point out what I am doing wrong.
      >
      I have a dll file that I dont want to use in my program, I just want to
      use the functions
      in my program.
      I do not understand the above, if you are using the methods of the DLL you
      are using the DLL
      >
      What do I need to do here to get this to work?
      What errors are you getting?


      Comment

      • John Rogers

        #4
        Re: Question about multiple namespace

        I do not understand the above, if you are using the methods of the DLL you
        are using the DLL
        I am not trying to use the DLL, I just want to use the functions from the
        dll, but I want the
        functions in my program and not an external dll file.


        Comment

        • John Rogers

          #5
          Re: Question about multiple namespace

          Well, you haven't shown where or how TextBox1 is declared. Is it
          declared to be a MyTextBox? Does that part work, barring access to
          Settings?
          I am not really sure I understand. The RichTextBox (TextBox1) is in the
          program, but settings does not exit as a property for RichTextBox.

          private void frmMain_Load(ob ject sender, EventArgs e)
          {
          RichTextBox1.Se ttings.Keywords .Add("function" );
          }

          Since I am moving the functions from an external DLL file into my program, I
          don't
          know how to make the functions accessible even though everything is within
          the
          same scope (i think).


          Comment

          • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

            #6
            Re: Question about multiple namespace



            "John Rogers" wrote:
            Well, you haven't shown where or how TextBox1 is declared. Is it
            declared to be a MyTextBox? Does that part work, barring access to
            Settings?
            >
            I am not really sure I understand. The RichTextBox (TextBox1) is in the
            program, but settings does not exit as a property for RichTextBox.
            >
            private void frmMain_Load(ob ject sender, EventArgs e)
            {
            RichTextBox1.Se ttings.Keywords .Add("function" );
            }
            >
            Since I am moving the functions from an external DLL file into my program, I
            don't
            know how to make the functions accessible even though everything is within
            the
            same scope (i think).
            >
            It sounds like you want a static function Settings contained in some class.
            You cannot call a method on any random class. When the code was in a
            different dll, how did you call the method Settings()? You weren't calling
            it on a RichTextBox, right?
            >

            Comment

            • John Rogers

              #7
              Re: Question about multiple namespace

              It sounds like you want a static function Settings contained in some
              class.
              You cannot call a method on any random class. When the code was in a
              different dll, how did you call the method Settings()? You weren't
              calling
              it on a RichTextBox, right?
              Yes it was calling the RichTextBox by its actual name.

              // DLL File
              using System;
              using System.Collecti ons.Generic;
              using System.Text;
              using System.IO;
              using System.Windows. Forms;
              using System.Componen tModel;
              using System.Text.Reg ularExpressions ;
              using System.Drawing;

              namespace SyntaxHighlight er
              {
              public class SyntaxRichTextB ox : System.Windows. Forms.RichTextB ox
              {
              private SyntaxSettings m_settings = new SyntaxSettings( );
              private int m_nCurSelection = 0;

              /// The settings.
              public SyntaxSettings Settings
              {
              get { return m_settings; }
              }
              etc. etc.
              }
              }
              // --------------------------------------------------
              // Other file using the dll file
              using System;
              using System.Collecti ons.Generic;
              using System.Componen tModel;
              using System.Data;
              using System.Drawing;
              using System.Text;
              using System.Windows. Forms;

              namespace SyntaxTester
              {
              private void MainForm_Load(o bject sender, EventArgs e)
              {
              // Add the keywords to the list.
              m_syntaxRichTex tBox.Settings.K eywords.Add("fu nction");
              m_syntaxRichTex tBox.Settings.K eywords.Add("if ");

              etc. etc.

              I am noticing some more code in the MainForm.Design er.cs that I had not
              noticed before.

              private void InitializeCompo nent()
              {
              this.m_syntaxRi chTextBox = new
              SyntaxHighlight er.SyntaxRichTe xtBox();
              this.m_buttonQu it = new System.Windows. Forms.Button();


              #endregion

              private SyntaxHighlight er.SyntaxRichTe xtBox m_syntaxRichTex tBox;
              private System.Windows. Forms.Button m_buttonQuit;


              I am assuming that I have to put this code into my Form1.Designer. cs file
              too?
              This is pretty new to me, I would appreciate any hand holding here. I
              always seem
              to start with the tough stuff first.

              Thanks



              Comment

              • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

                #8
                Re: Question about multiple namespace



                "John Rogers" wrote:
                It sounds like you want a static function Settings contained in some
                class.
                You cannot call a method on any random class. When the code was in a
                different dll, how did you call the method Settings()? You weren't
                calling
                it on a RichTextBox, right?
                >
                Yes it was calling the RichTextBox by its actual name.
                >
                // DLL File
                using System;
                using System.Collecti ons.Generic;
                using System.Text;
                using System.IO;
                using System.Windows. Forms;
                using System.Componen tModel;
                using System.Text.Reg ularExpressions ;
                using System.Drawing;
                >
                namespace SyntaxHighlight er
                {
                public class SyntaxRichTextB ox : System.Windows. Forms.RichTextB ox
                {
                private SyntaxSettings m_settings = new SyntaxSettings( );
                private int m_nCurSelection = 0;
                >
                /// The settings.
                public SyntaxSettings Settings
                {
                get { return m_settings; }
                }
                etc. etc.
                }
                }

                OK, so if you put the above class in your new project, you should be able to
                create an instance of a SyntaxRichTextB ox , add it to a form, and call
                Settings on any instance. You cannot creat an instance of a RichTextBox and
                call Settings on that object however.

                You will also need to bring SyntaxSettings class into the project.

                Does this help, or am I missing your problem (quite possible!).


                Comment

                • Ignacio Machin \( .NET/ C# MVP \)

                  #9
                  Re: Question about multiple namespace

                  Hi,

                  --
                  Ignacio Machin
                  The #1 Warehouse Management System & Direct Store Delivery Software (DSD) for QuickBooks & ERP Systems – LaceUp Solutions

                  Mobile & warehouse Solutions.
                  "John Rogers" <johnrogers2345 @aol.comwrote in message
                  news:ufQiMGDSIH A.4440@TK2MSFTN GP06.phx.gbl...
                  >I do not understand the above, if you are using the methods of the DLL
                  >you are using the DLL
                  >
                  I am not trying to use the DLL, I just want to use the functions from the
                  dll, but I want the
                  And what is the difference between both statements? "using a dll" is "using
                  the methods of the dll"
                  functions in my program and not an external dll file.
                  Do you mean that you want to embed the dll in your .EXE ?


                  Comment

                  • Jon Skeet [C# MVP]

                    #10
                    Re: Question about multiple namespace

                    John Rogers <johnrogers2345 @aol.comwrote:

                    <snip>
                    I am assuming that I have to put this code into my Form1.Designer. cs file
                    too?
                    It's hard to say - all the names keep changing in each post. First
                    there was frmMain, then Form1, then MainForm - and likewise there was
                    MyRichTextBox, then RichTextBox, then SyntaxRichTextB ox. That makes it
                    really hard to keep track of what you've *actually* got where.

                    Could you post a short but complete program which demonstrates the
                    problem?

                    See http://www.pobox.com/~skeet/csharp/complete.html for details of
                    what I mean by that.

                    --
                    Jon Skeet - <skeet@pobox.co m>
                    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                    World class .NET training in the UK: http://iterativetraining.co.uk

                    Comment

                    • John Rogers

                      #11
                      Re: Question about multiple namespace

                      It's hard to say - all the names keep changing in each post. First
                      there was frmMain, then Form1, then MainForm - and likewise there was
                      MyRichTextBox, then RichTextBox, then SyntaxRichTextB ox. That makes it
                      really hard to keep track of what you've *actually* got where.
                      Sorry about that, I have been posting from my pc and at a friends house.
                      I did get it to work, I just added in the information to the
                      Form1.Designer. cs
                      and it worked.


                      Comment

                      • Jon Skeet [C# MVP]

                        #12
                        Re: Question about multiple namespace

                        John Rogers <johnrogers2345 @aol.comwrote:
                        It's hard to say - all the names keep changing in each post. First
                        there was frmMain, then Form1, then MainForm - and likewise there was
                        MyRichTextBox, then RichTextBox, then SyntaxRichTextB ox. That makes it
                        really hard to keep track of what you've *actually* got where.
                        >
                        Sorry about that, I have been posting from my pc and at a friends house.
                        I did get it to work, I just added in the information to the
                        Form1.Designer. cs
                        and it worked.
                        Well, that's a bit worrying - you should never need to touch the
                        designer files yourself, they're "owned" by the designer, and will be
                        recreated next time you change something in the designer.

                        --
                        Jon Skeet - <skeet@pobox.co m>
                        http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                        World class .NET training in the UK: http://iterativetraining.co.uk

                        Comment

                        Working...