|
To understand the reason why C# prevents you from doing this, you need to understand the basics of value types (or structures).
Unlike reference types, when value types are returned from methods (or set via an assignment), a copy of the value type is returned and not the orginal version.
In the situation above, Form.Size is a property (which is a method underneath) and it returns the Size value type.
So when you attempt to assign a value to Size.Height, you are actually attempting to assign it to a copy and not the underlying Size structure.
Although, it is technically valid to do this, the C# compiler makes the assumption that this is not what you want to do, and hence fires the compiler error.
Excelsior
Arjun Bahree
"By The Might of Mjolnir"
I Came! I Coded! I Conquered!
|
|
|
|
|
Use a this.Height instead of this.Size.Height and it will work.
Excelsior
Arjun Bahree
"By The Might of Mjolnir"
I Came! I Coded! I Conquered!
|
|
|
|
|
Thx guys!
This effort for now was useless.
My content isnt resizing, so i cannot see this working.
Basicly i have three kind of elements in this form:
- web browser
- media player
- picture box
I want this form to popup when i click previw in a list of element of several file types.
For now i'm just focusing in videos.
I want my media player to resize to current video's size.
Is there any easy way of doing that, without having to see the movies information in order to get its size?
Thx,
Nuno
|
|
|
|
|
Hi,
I'm building a MDI application which child forms will be running inside a splitContainer panel.
Well, when i maximize i have two problems:
- The form title bar seems weird (usually, in other applications, the title bar gets flat and not with that rounded blue thing)
- If i move the spliter, the windows doesnt get maximized automaticly.
Is there anything i can do to solve this?
Thx
Nuno
|
|
|
|
|
I am developing an xml playlist(in attribute style) based slide show. I am able to read all the information from xml assign them to variables and then to respective picture boxes and text box. The problem is it waits till the end of the loop to go back to the function that called this process in the form_load method and then display the last file in the play list and exit the loop without ever displaying the first two images
private void Form1_Load(object sender, EventArgs e)
{
CheckForFile(); }
public void CheckForFile() {
LoadPlaylist((System.Convert.ToString(@"C:\PlayerLibrary\config\ab.xml")));
}
public void LoadPlaylist(string strFileName)
{
string strItemName = "";
XmlTextReader playlistReader = new XmlTextReader(strFileName);
while (playlistReader.Read() && (playlistReader.NodeType == XmlNodeType.Element || playlistReader.NodeType == XmlNodeType.Whitespace))
{
if (playlistReader.HasAttributes && playlistReader.Name == "name")
{
strItemName = playlistReader.GetAttribute("location");
playFile(strItemName);
break;
} } playlistReader.Close(); }
public void playFile(string playFileName)
{
string fileExtention = "";
fileExtention = playFileName.Substring(playFileName.Length - 3, 3);
//check if the file is image type then display it using pBoxPlayer
if (fileExtention == "bmp" || fileExtention == "jpg" || fileExtention == "JPG" || fileExtention == "BMP" || fileExtention == "gif" || fileExtention == "Gif" || fileExtention == "PNG" || fileExtention == "png")
{
this.pBoxPlayer.Load(playFileName);
this.pBoxPlayer.Visible = true;
this.Show();
this.pBoxPlayer.Show();
} } }
sam
|
|
|
|
|
Hello,
If you really whant to stay with the loop, you have to work with:
this.Refresh();
Application.DoEvents();
Thread.Sleep(xxx);
I would rather get the informations out of the XML and then use a Timer to step threw the list.
All the best,
Martin
|
|
|
|
|
Dear CPians,
I have been working with the Xml.Serialization namespace in order to serialize C# objects to Xml. In some of my Classes I have long string members that I need to enclose within CDATA sections when serialized. I have been struggling to find a way to do this.
Any ideas?
Thanking you in advance.
|
|
|
|
|
Hi,
I'm just knocking up a quick program which works out how much savings I can save by entering a deposit, a number of weeks i want to save and then outputting me a total. I have got the program working fine, but if my total saving were £150.50 my total field only displays £150.5
Is there a currency format i'm missing? Here's my code:
namespace Savings_Calculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double deposit;
int weeks;
double total;
private void btnCalculate_Click(object sender, EventArgs e)
{
deposit = Convert.ToDouble(txtDeposit.Text);
weeks = Convert.ToInt32(txtWeeks.Text);
total = deposit * weeks;
txtTotal.Text = "£" + Convert.ToString(total);
}
Many thanks.
|
|
|
|
|
I guess it would be best to use the 'decimal' type, and you can print it nicely with .ToString("N2") (2 decimals displayed)
Visual Studio can't evaluate this, can you?
public object moo<br />
{<br />
__get { return moo; }<br />
__set { moo = value; }<br />
}
|
|
|
|
|
Hi all, I'm hoping someone ca help me out here as I've been stuck on this one for a while now.
I have a DLL (written in C++) that exposes the following function:
int sendAPDU (byte* TxAPDU, int TxLen, byte* RxAPDU, int* RxLen)
Essentially, this function takes an array of bytes (TxAPDU) with TxLen elements and returns an array of byte (RxAPDU) with RxLen elements. The key issue here which is throwing me is the fact that the last two parameters are reference parameters (or strictly speaking output parameters).
My problem is that, in C#, I can't seem to figure out how to import that function from the DLL and call it. I thought it would be something like:
[DllImport("MyLibrary.dll", EntryPoint = "sendAPDU")]<br />
public static extern int sendAPDU(Byte[] TxAPDU, int TxLen, ref Byte[] RxAPDU, ref int RxLen);
And then when calling the function it'd be something like:
Byte [] TxArray = new Byte[26];<br />
Byte [] RxArray = new Byte[MAX_APDU_LEN];<br />
int RxLength;<br />
<br />
int retval = sendAPDU (TxArray, 26, ref RxArray, ref RxLen);
So what is it that I'm doing wrong? Forgive me if this is a straight forward issue but I'm ew to C#.
|
|
|
|
|
Hi..
I don't know if i can help you on this because i'm not very experienced about PInvoke but just a few thoughts:
1. You have to possibility to Marshal Function Parameters in .Net so maybe the MarshalAs - Attribute could help you.
something like:
<br />
[DllImport("MyLibrary.dll", EntryPoint = "sendAPDU")]<br />
public static extern int sendAPDU([MarshalAs(UnmanagedType.LPArray)] Byte[] TxAPDU, int TxLen, [MarshalAs(UnmanagedType.LPArray)]ref Byte[] RxAPDU, ref int RxLen);<br />
the MarshalAs Attribute can be found under System.Runtime.InteropServices
2. i don't know if this makes a difference in PInvoke but did you try to use out instead of ref for your output parameters?
greets
m@u
|
|
|
|
|
Thanks m@u. I was afraid it might have something to do with Marshaling because I bumped into that once before and never really figured it out. I suppose I still don't understand this whole managed memory versus unmanaged memory thing.
At any rate, I tried your suggestion and read up on the MarshalAs attribute but it still didn't solve my problem and I still don't think I really understand how to use this MarshalAs attribute but to my great relief, the solution to my problem popped out of virtually nowhere.
The C++ programmer in me still pondered on this principle of passing pointers as funtion parameters and it occured to me that, if in C++ passing an array and passing a pointer is one and the same thing, doesn't the same apply for C# and reference parameters?
So I changed my function declaration which follows the DLLImport attribute from:
public static extern int sendAPDU(Byte[] TxAPDU, int TxLen, ref Byte[] RxAPDU, ref int RxLen);
to:
public static extern int sendAPDU(Byte[] TxAPDU, int TxLen, Byte[] RxAPDU, ref int RxLen);
and would you believe it, it works!
I'm still unsure about the memory management issue that this introduces. In C++ this would have left room for serious memory overflow issues, so what happens in C# if you call a function from a DLL written in C++? Let's say, I have a function like this:
public static extern int myFunc(byte[] ByteArray);
which, in the DLL, does something like this:
ByteArray[10] = 10;
Now, if you call this from C# like this:
byte[] sendArray = { 1, 2, 3 };<br />
int retval = myFunc(sendArray);
Clearly in C++ this would have written the value 10 into memory, 7 bytes past the end of the memory allocated to sendArray, causing havoc. So what happens when you call the DLL function from C#?
Sorry guys, I realise that this is one of the central issues to C# and you can't claim to be a C# programmer if you don't understand managed vs. unmanaged memory. But I am a noob.
|
|
|
|
|
Hi,
I would like to know, what are advantages and disadvantages of two template generators:
Guidance Automation Toolkit and Code Smith?
Is it better to develop templates using Code Smith or to develop packages with GAT?
What you think about this both tools?
Wojtek
|
|
|
|
|
Hello,
I am having diffiulty in calling a function from the parent form from the child form without having to create a new instance of the parent form.
Parent form spawns child which upon clicking of a button deletes a member from a database. What I need the button to do is to refresh a table on the parent form.
I have tried overriding refresh on the parent form but I still get the same issue: a nullpointerexception and the parent form is closed as well.
The code in the child form is this:
MessageBox.Show("Occurence Deleted!");
this.Parent.Refresh();
this.Close();
This is the override I have in the parent form:
public override void Refresh()
{
DataSet ds = eo.GetSearch();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Employees";
}
The exception I am receiveing is:
A first chance exception of type 'System.NullReferenceException' occurred in Occurence Manager.exe
System.NullReferenceException: Object reference not set to an instance of an object.
(which is at the following line : this.Parent.Refresh();
What am I doing wrong?
|
|
|
|
|
First of all, I would call your refresh routine by a different name. Secondly, cast your Parent variable. So, suppose that your method was called RefreshData and the parent form was called MyParent, you would call it like this
((MyParent)this.Parent).RefreshData();
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I'm still having the same problem with the exception however. When I run the code in the parent form (via a refresh button) it runs just fine and does what it's supposed to do. I am trying to run this code in the child form after it makes edits to the database but unfortunately it still gives me an exception and closes the parent form.
could it be that the parent form (of the child in question) itself is passed a variable from a (grand?)parent form (the main form) and passes that variable into a protected variable upon initialization?
Here is the form in question expanded:
public partial class SearchWindow : Form
{
EmployeeObject eo;
DataSet ds = new DataSet();
public SearchWindow(EmployeeObject o)
{
InitializeComponent();
eo = o;
//RefreshData();
ds = eo.GetSearch();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Employees";
}
public void RefreshData()
{
// ds = eo.GetSearch();
//dataGridView1.DataSource = ds;
//dataGridView1.DataMember = "Employees";
}
... and so on.
|
|
|
|
|
Sounds like you haven't set the parent of the child form then. The null reference obviously indicates this.Parent.RefreshData();
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I'm running into all sorts of trouble just to try to refresh a window. =)
Anyways I set the parent using this:
eef.Parent = this;
(eef being the instance of the child form)
then displayed it with eef.ShowDialog();
but unfortunately the window does not show and additionally it closes the parent form!
I get this exception: System.ArgumentException: Top-level control cannot be added to a control.
I can't do eef.ParentForm = this; because .ParentForm is read only.
I had assumed earlier however that when you instantiated a child form that it would automatically inherit the parent form.
|
|
|
|
|
I asked this question on the MSDN forums and this was the response:
Try setting the Owner property of the Dialog window:
using(frmMyDialog eef = new frmMyDialog())
{
eef.ShowDialog(this);
}
And in your dialog window:
(this.Owner as frmSearchWindow).RefreshData();
And it worked beautifully. =)
Apparently I needed to set the owner property instead of the parent property.
|
|
|
|
|
|
What is a "help privilege"?
|
|
|
|
|
Please don't send me emails; the forum is best for answering questions because others can then see the answer and benefit from it as well.
|
|
|
|
|
sorry i was mistraken,
anyway thnx for ur kind help
prashanth
|
|
|
|
|
How I can install programs from server to client using c#?
|
|
|
|
|
That's too broad of a question to give you any meaningful answer. If you need to do interprocess communication, look up .NET remoting. For installing stuff, potentially you could send the setup files across the pipe to the client, then the client could use System.Diagnostics.Process to launch the setup file. Most installers have a silent mode you can specify in the Process's arguments if you want the installer to run without intervention.
|
|
|
|