473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Passing object as parameter such as RichTextBox

Good day,

I am basically writing a generic namespace with various helper classes.
I don't want to add the calling form to the referrences.

Example of what I am trying to do. Please let me know if i am going in
the wrong direction. I am rather new to C# and .NET.

I have a form in another namespace that on a button click I call
DoProcessing and pass the RichTextBox to log to.

namespace Utils
{
class MiscUtils
{
RichTextBox LogRichTextBox = null;

public static void DoProcessing(RichTextBox aRichTextBox)
{
LogRichTextBox = aRichTextBox;
PrintOutput("A Message");
}

public static void PrintOutput(string aMessage)
{
if (LogRichTextBox != null)
{
LogRichTextBox.AppendText(aMessage);
{
}
}
}

Jul 20 '06 #1
2 3393
Markus,

That's fine, you wouldn't need to have a reference to your form, you
just have to pass the RichTextBox in (which would require a reference to
System.Windows.Forms, but I think you are ok with that).

Hope this helps.
"MarkusR" <ma*******@gmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
Good day,

I am basically writing a generic namespace with various helper classes.
I don't want to add the calling form to the referrences.

Example of what I am trying to do. Please let me know if i am going in
the wrong direction. I am rather new to C# and .NET.

I have a form in another namespace that on a button click I call
DoProcessing and pass the RichTextBox to log to.

namespace Utils
{
class MiscUtils
{
RichTextBox LogRichTextBox = null;

public static void DoProcessing(RichTextBox aRichTextBox)
{
LogRichTextBox = aRichTextBox;
PrintOutput("A Message");
}

public static void PrintOutput(string aMessage)
{
if (LogRichTextBox != null)
{
LogRichTextBox.AppendText(aMessage);
{
}
}
}

Jul 20 '06 #2
I figured it out. Sorry, I am a newbie at c#.

This is how I did it:

In the form:

private void button1_Click(object sender, EventArgs e)
{
MiscUtils myUtil = new ProcessLotUtils(mLog);
myUtil.DoProcessing();
}

In my utility namespace:

namespace Utils
{
class MiscUtils
{
RichTextBox LogRichTextBox = null;

// Default constructor:
public MiscUtils()
{
LogRichTextBox = null;
}

// Constructor:
public MiscUtils(RichTextBox aRichTextBox)
{
LogRichTextBox = aRichTextBox;
}

public void DoProcessing()
{
PrintOutput("A Message");
}

public static void PrintOutput(string aMessage)
{
if (LogRichTextBox != null)
{
LogRichTextBox.AppendText(aMessage);
{
}
}
}

Hopefully there aren't any types. Just typed up the example.

Thanks Nicholas for your help.

-Markus

Jul 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andy | last post by:
Hi Could someone clarify for me the method parameter passing concept? As I understand it, if you pass a variable without the "ref" syntax then it gets passed as a copy. If you pass a...
9
by: Tom | last post by:
I am working with the this object as oppose to the StreamReader object becuase I need to access a file (to find the contents) while an external application is updating the file. When I was...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
6
by: MSDNAndi | last post by:
Hi, I get the following warning: "Possibly incorrect assignment to local 'oLockObject' which is the argument to a using or lock statement. The Dispose call or unlocking will happen on the...
0
by: njuneardave | last post by:
Hey, I am trying to create a function that will attempt to find a word in a rich text box. I have 5 different tabs on a tab control box.....each tab has one RTB. i want to perform the search on...
10
by: amazon | last post by:
Our vender provided us a web service: 1xyztest.xsd file... ------------------------------------ postEvent PostEventRequest ------------------------------------- authetication authentication...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
12
by: dave_dp | last post by:
Hi, I have just started learning C++ language.. I've read much even tried to understand the way standard says but still can't get the grasp of that concept. When parameters are passed/returned...
4
by: Deckarep | last post by:
Hello fellow C# programmers, This question is more about general practice and convention so here goes: I got into a discussion with a co-worker who insisted that as a general practice all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.