Question about multiple namespace

R

Rob Stevens

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()
{
InitializeComponent();
}

// 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(object sender, EventArgs e)
{
TextBox1.Settings.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
 
J

Jon Skeet [C# MVP]

Rob Stevens said:
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?
 
I

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

Hi,
+

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Rob Stevens said:
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?
 
J

John Rogers

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.
 
J

John Rogers

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(object sender, EventArgs e)
{
RichTextBox1.Settings.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).
 
F

Family Tree Mike

John Rogers said:
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(object sender, EventArgs e)
{
RichTextBox1.Settings.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?
 
J

John Rogers

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.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Drawing;

namespace SyntaxHighlighter
{
public class SyntaxRichTextBox : System.Windows.Forms.RichTextBox
{
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.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SyntaxTester
{
private void MainForm_Load(object sender, EventArgs e)
{
// Add the keywords to the list.
m_syntaxRichTextBox.Settings.Keywords.Add("function");
m_syntaxRichTextBox.Settings.Keywords.Add("if");

etc. etc.

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

private void InitializeComponent()
{
this.m_syntaxRichTextBox = new
SyntaxHighlighter.SyntaxRichTextBox();
this.m_buttonQuit = new System.Windows.Forms.Button();


#endregion

private SyntaxHighlighter.SyntaxRichTextBox m_syntaxRichTextBox;
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
 
F

Family Tree Mike

John Rogers said:
Yes it was calling the RichTextBox by its actual name.

// DLL File
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Drawing;

namespace SyntaxHighlighter
{
public class SyntaxRichTextBox : System.Windows.Forms.RichTextBox
{
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 SyntaxRichTextBox , 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!).
 
I

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

Hi,

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
John Rogers said:
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 ?
 
J

Jon Skeet [C# MVP]

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 SyntaxRichTextBox. 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.
 
J

John Rogers

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 SyntaxRichTextBox. 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.
 
J

Jon Skeet [C# MVP]

John Rogers said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top