473,385 Members | 1,523 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,385 software developers and data experts.

Var/Object Access

Cant access a object that is in the same class it seems...
With a new c# win. app. project in vis studio 2k5, if I want to access a
richTextBox that was defined in Form1.Designer.cs. (richTextBox1).

I write a simple line in program.cs
richTextBox1.Text="Test 1.1";

Essentially richTextBox1 is unknown to program.cs ?
so I figured there was a proper name to this textbox

Form1.richTextBox1 ?

So my question is how to access objects from the partial class Form1 ?
Jan 5 '06 #1
2 1567
Firstly, they aren't the same class: one is Form1, and the other is Program

Secondly, the control is (by default) private. And rightly so. You could
make this "internal" or "public", but I wouldn't recommed it. Better to
expose this via a custom property on Form1:

public string RichText {
set { richTextBox1.Text = value; }
get { return richTextBox1.Text; }
}
Thirdly, in C# (and .Net generally) there is no automatic default instance
of (for instance) a form, so you need to work with an instantiated instance
of the form - something like (in Program.cs)
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
using (Form1 formInstance = new Form1()) {
formInstance.RichText = "Test 1.1";
Application.Run(formInstance);
}
}

Would you be moving over from VB6 by any chance? I guess this from the
Form1.richTextBox1 line.

The code above works fine for me.

Marc

"Christopher" <Ch*********@discussions.microsoft.com> wrote in message
news:C8**********************************@microsof t.com...
Cant access a object that is in the same class it seems...
With a new c# win. app. project in vis studio 2k5, if I want to access a
richTextBox that was defined in Form1.Designer.cs. (richTextBox1).

I write a simple line in program.cs
richTextBox1.Text="Test 1.1";

Essentially richTextBox1 is unknown to program.cs ?
so I figured there was a proper name to this textbox

Form1.richTextBox1 ?

So my question is how to access objects from the partial class Form1 ?

Jan 5 '06 #2
Thanks for the reply..

"> static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
using (Form1 formInstance = new Form1()) {
formInstance.RichText = "Test 1.1";
Application.Run(formInstance);
}
}

Would you be moving over from VB6 by any chance? I guess this from the
Form1.richTextBox1 line.


Well that was just silly of me , I was confused by the partial class
declarations.

Thanks
Jan 5 '06 #3

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

Similar topics

18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
4
by: Dave Kolb | last post by:
If I make ASPNET a member of the admins group it can launch my COM+ object but I do not want to do that. What permissions do I need to set for the lowly ASPNET user so that it can launch a COM+...
3
by: Shawn | last post by:
Hi. In my application I store information about the user in the session object. Since I'm storing sensitive information I encrypt it before storing and decrypt it when I need to use it again. The...
4
by: Luke Matuszewski | last post by:
Here are some questions that i am interested about and wanted to here an explanation/discussion: 1. (general) Is the objectness in JavaScript was supported from the very first version of it (in...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
4
by: gg9h0st | last post by:
i'm a newbie studying php. i was into array part on tutorial and it says i'll get an array having keys that from member variable's name by converting an object to array. i guessed "i can...
2
by: Crimson* | last post by:
I've got a table with an entry type as "OLE Object" in Access 2003. In the form that the table is linked to I want to insert an image (BMP) for each record. However, when I attempt to do so the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.