am trying to add controls (e.g. radio buttons, group boxes) to a
windows form in a method which I call from the constructor.
However, when I do things like;
RadioButton rb= new RadioButton();
....
rb.Location.X= 67;
this.Controls.A dd(rb); // this is the Windows Form instance
I am told that;
"Cannot modify the return value of
'System.Window. Forms.Control.L ocatoin' because it is not a variable"
I have tried to use CreateControl() but it doesn't seem to have any
effect.
If anyone knows how to do this please help asap
John 4 2383
John,
The reason that this doesn't work is because Location is of type Point,
which is a value type. When you return value types from properties or
methods (through the return value, not ref parameters), a copy is made and
returned to you.
That being said, when you do this:
rb.Location.X= 67;
You are setting the X property/field on a copy returned to you. To
perform this operation, you would need to do this:
// Store the location.
Point temp = rb.Location;
// Set the X value.
temp.X = 67;
// Set the location back.
rb.Location = temp;
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
<jo************ @googlemail.com > wrote in message
news:11******** ************@z1 4g2000cwz.googl egroups.com... am trying to add controls (e.g. radio buttons, group boxes) to a windows form in a method which I call from the constructor.
However, when I do things like;
RadioButton rb= new RadioButton(); ... rb.Location.X= 67;
this.Controls.A dd(rb); // this is the Windows Form instance
I am told that;
"Cannot modify the return value of 'System.Window. Forms.Control.L ocatoin' because it is not a variable"
I have tried to use CreateControl() but it doesn't seem to have any effect.
If anyone knows how to do this please help asap
John
The Location property is of type System.Drawing. Point (a struct). This
means that accessing the button's Location property returns a copy of
the struct, and since this is not assigned to a variable it cannot be
modified. (Even if the compiler let this through you would still have
been modifying a temporary variable, and it would have no effect on the
button).
Instead, use
rb.Location = new Point(x, y);
Jon.
Hi,
Additionaly to Nicholas comment you can use Left to set a new position.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<jo************ @googlemail.com > wrote in message
news:11******** ************@z1 4g2000cwz.googl egroups.com... am trying to add controls (e.g. radio buttons, group boxes) to a windows form in a method which I call from the constructor.
However, when I do things like;
RadioButton rb= new RadioButton(); ... rb.Location.X= 67;
this.Controls.A dd(rb); // this is the Windows Form instance
I am told that;
"Cannot modify the return value of 'System.Window. Forms.Control.L ocatoin' because it is not a variable"
I have tried to use CreateControl() but it doesn't seem to have any effect.
If anyone knows how to do this please help asap
John
[reply to all]
thanks all for your help. I went for the option Nicholas posted. It's
got past the compiler and it's now up to me to make sure my algorithm
is right.
Thanks again all
John This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mike Malter |
last post by:
I take it that the only way to add rows to a DataList control is through DataBind?
If not, how do I manually add rows to a DataList control? I have searched everywhere and can't find an example anywhere other than
through building a DataTable, and then doing a DataBind.
Thanks.
Mike
|
by: Jim Heavey |
last post by:
Trying to figure out the technique which should be used
to add rows to a datagrid. I am thinking that I would
want an "Add" button on the footer, but I am not quite
sure how to do that. Is that the best method? Do you
have a sample of how to do this?
|
by: Praveen Ramesh |
last post by:
Hi,
Is there any way to add the @Assembly reference to the aspx files
programmatically from inside a custom control (when it gets dropped on to
the page from the toolbox)?
I have a custom control - MyControl that implements an interface in another
custom assembly - InterfaceAssembly. When MyControl gets dropped on to the
page and run, it results in a "InterfaceAssembly not found" exception. I am
aware that this can be fixed by...
|
by: johnb41 |
last post by:
I want to create a textbox programmatically and add the SAME textbox to
to different panels. This code does not work:
Dim tb As New TextBox
tb.text = "xyz"
Panel1.Controls.Add(tb)
Panel2.Controls.Add(tb)
The textbox gets added to Panel2, but not Panel1. How can i get the
textbox to go to both panels? I can get it to work by duplicating the
|
by: |
last post by:
I have made some user controls with custom properties. I can set those
properties on instances of my user controls, and I have programmed my user
control to do useful visual things in response to how those properties are
set.
I want to be able to do two other things:
a) add User control instances to my page, filling in the place of
placeholder controls, and
b) programmatically setting custom properties on those dynamically spawned...
| |
by: Wayne Deleer |
last post by:
Hi All,
I'm currently working on a project, and I've come to a part where I
want to add data to a GridView. BUT, I want to do it programmatically,
with alot of control over everything. In my particular project I've
passed a DataSet to a page via a Session object. The Session object
passes without incident, and I can use the default settings to retrieve
the information without problem and plug all the information into the
GridView.
|
by: ChrisCicc |
last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have been able to find the cause of the problem, and will describe it here first textually and then through a code example.
The purpose of what I am trying to do is to create a postback-free web application through the use of ASP.net AJAX UpdatePanels...
|
by: alun65 |
last post by:
I'm attempting to programmatically build up some HTML in the code
behind. Like so:
// Create Hyperlink
HyperLink link = new HyperLink();
link.NavigateUrl = "nice cat";
link.Text = "Cats Sleeping";
//Create Image
Image img = new Image();
|
by: alun65 |
last post by:
I'm having trouble programmatically adding a user control and then
setting some of it's server controls.
I add the user control to the code behind and add it to a placeholder:
protected void Page_Load(object sender, EventArgs e)
{
UserControls_WebUserControl myControl = new
UserControls_WebUserControl();
PlaceHolder1.Controls.Add(web);
|
by: Nathan Sokalski |
last post by:
I have css that would normally be placed in style tags in the header of the
Master page that I want to add programmatically for a specific Web Content
Form (the *.aspx page). How do I do this for a Web Content Form? I cannot
use style tags in a Web Content Form, and I am having trouble figuring out
how to add all the desired css properties to a
System.Web.UI.WebControls.Style object. Can anyone help me? Thanks.
--
Nathan Sokalski...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |