|
CodingLover wrote: But the question is, that way is safe. I mean may be three arrays can be large.
If you don't have enough memory for the original arrays and the combined array, you could instead make a class that contains the arrays and can be used as a single array. Someting like:
public class ArrayCombiner<T> {
private List<T[]> _arrays = new List<T[]>();
private int _length = 0;
public void Add(T[] array) {
_arrays.Add(array);
_length += array.Length;
}
public int Length { get { return _length; } }
public T this[int index] {
get {
if (index < 0 || index >= _length) {
throw new IndexOutOfRangeException();
}
int array = 0;
while (index > _arrays[array].Length) {
index -= _arrays[array].Length;
array++;
}
return _arrays[array][index];
}
}
}
CodingLover wrote: And also in copy a bit can be shift.
What?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I am attempting to call the "ChangeDisplaySettings" function from the Win32 API which is supposed to update the display settings on the computer. It takes in a DEVMODE structure (also defined via the API) as an argument. The function is defined as:
public static extern int ChangeDisplaySettings(ref DEVMODE lpDevMode, int dwFlags);
Apparently, in C# you cannot pass the value "null" in the place of a DEVMODE because it is a nonnullable value. I am attempting to call "ChangeDisplaySettings(null, 0);" which is supposed to update the display settings strictly based on what the registry has but i get errors telling me it cannot convert "null" to a "ref DEVMODE". Does anyone know how i can either call the function in the way that i would like to in order to update the display based on the registry, or perform this same function in a different manner? Help is appreciated!!!!
THANKS!!!
-JDub
|
|
|
|
|
you can you script " " full null value
|
|
|
|
|
What do you mean by "script "" full null value"? If you dont mind, could you please provide a short example of what you mean or what i should be putting as the argument
|
|
|
|
|
Maybe something like this...
[DllImport("user32.dll")]
public static extern int ChangeDisplaySettings(ref DevMode devMode, int flags);
[DllImport("user32.dll")]
public static extern int ChangeDisplaySettings(IntPtr devMode, int flags);
...
ChangeDisplaySettings(IntPtr.Zero, 0);
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
That Worked Perfectly! I never thought about overloading the function. Thank you so much!
|
|
|
|
|
Thank you! excellent tip, that's work perfectly.
|
|
|
|
|
Just a quick overview,
I have controls which have a property of Type Type. The property grid doesn't by default support editing of it. So I have to inherit from UITypeEditor.
What my program currently does is display a form with all the types in the assembly my UITypeEditor is in and all the assemblies it references. This is not quite ideal because it should be the assembly the Form (or other control) that is being designed is in and all of it's references.
Any ideas?
Thanks in advance,
Chris
|
|
|
|
|
hi all,
i am using window.open() in C# aspx.cs the code works fine in ie6,mozilla but in ie7 and ie8 new window opens but it closes within 1 second.
here is my code.
Page.RegisterStartupScript("pop1", "window.open('" + url + "','mywindow');");
Is there any coding problem or browser ,please give some ideas regarding this.
Thanks
hivshi
|
|
|
|
|
Did you not see the ASP.NET forum ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
That code doesn't open the page in a new window, it opens the page in the window named "mywindow". It's only if there is no window with that name that a new window is opened. If you want to open a new window, you should use the target "_blank" instead of "mywindow".
There is nothing in the window.open method that could case the window to close after a second. There has to be something in the code in the page that you open that does that.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hi,
can anyone tell me how to handle the columns size of the datagridview.
i know the propriety but sometimes i d´ont know the lenght of the strings!!! so i get a big or small sized columns
is there something i can enable?
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
The AutoSizeMode property is probably what you're looking for.
Eslam Afifi
|
|
|
|
|
While AutoSize does a reasonable job I find manually sizing the column during development the most satisfactory. I have a function where I pass a CSV string of sizes after the grid is loaded and that sets the column widths, including hiding 0 width columns which I always have as column 0 holds the ID for the row .
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Create a C# Windows Application. Replace the non-designer class code in the Form with mine below.
The code simply creates 10 Panels on the form, each with one button on it. I assign each button's parent panel to the button's "Tag" property. I assign one common click event handler to all the buttons. In the click event handler, I simply cast the button's "Tag" to a Panel, then do a Form.Controls.Remove() to remove the Panel from the Form's "Controls" collection.
I also create a "debug" window so that I can see when the button click event handler fires.
Run the application and start hitting the spacebar. Exactly as you would expect, as you "click" each button by hitting the spacebar, the respective panel is removed. But keep hitting the spacebar after no more panels are visible. The click event KEEPS ON FIRING. I can understand that the panel can still be alive (and not have been garbage collected) and still have the button in its' "Controls" collection. But how does the spacebar keypress get from the form (which is in focus and has Controls.Count = 0) to the panel (and on to the button) that is no longer in its "Controls" collection???
public partial class Form1 : Form
{
private Form debugForm;
private TextBox debugTextBox;
public Form1()
{
InitializeComponent();
}
void b_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
Panel p = (Panel)(b.Tag);
this.Controls.Remove(p);
debugTextBox.Text += "Click event fired for " + b.Name + " : this.Controls.Count = " +
this.Controls.Count.ToString() + "\r\n";
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
debugForm.Close();
}
catch { }
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
Panel p = new Panel();
p.Left = 0;
p.Top = i * 35;
p.Width = 300;
p.Height = 30;
Button b = new Button();
b.Left = 0;
b.Top = 0;
b.Width = 300;
b.Height = 30;
b.Name = b.Text = "Button" + i.ToString();
b.Click += new EventHandler(b_Click);
b.Tag = p;
p.Controls.Add(b);
this.Controls.Add(p);
}
Rectangle rScreen = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
this.Left = 0;
this.Width = rScreen.Width / 2;
this.Top = 0;
this.Height = rScreen.Height;
debugForm = new Form();
debugForm.StartPosition = FormStartPosition.Manual;
debugForm.Left = this.Right + 1;
debugForm.Width = this.Width;
debugForm.Top = this.Top;
debugForm.Height = this.Height;
debugTextBox = new TextBox();
debugTextBox.Multiline = true;
debugTextBox.Dock = DockStyle.Fill;
debugTextBox.ScrollBars = ScrollBars.Both;
debugForm.Controls.Add(debugTextBox);
debugForm.Show();
}
}
|
|
|
|
|
I was working on my project and all my tool strip items, label, combo box ect..disappeared. I can still reference the objects in my code, but I cannot see the items even in Visual Studio.
Thanks!
|
|
|
|
|
Hi,
My question is basicly the title. What are the differences in C# between those two? If I implement a Vector3 class (X, Y and Z, all float member). Why would I use struct instead of class? How do I choose? The sintax is pretty much the same... (as I see)
Thanks,
Dirso
|
|
|
|
|
|
Is google broken where you live ? Did someone steal all your reference books ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Calm down! You don't have to be that rude. Sorry if my question has offended you in anyway - it was not my intention. The previous guy has already sent me to google.
I already undertood what you (both) meant and I'll be more carefull next time before posting a question.
Thanks,
Dirso
|
|
|
|
|
Dirso, it's just that this is a question that has been asked so many times! No hard feelings, we just tell people to look at Google, as it's been asked and answered so many times.
Since you've been good about it, I will fill you in on a few things:
Classes:
* stored on the heap
* require garbage collection (thus, more heavyweight than structs)
* when passed to a function, you're passing a reference ("pointer") to the original object
Contrast this with structs:
* stored on the stack
* no need for garbage collection (thus, much more lightweight)
* when passed to a function, a copy of the object is made
|
|
|
|
|
Thank you so much for this information!
I actually was not sad with you, you're right, I should gougle it first, but yesterday I posted a few questions after googling with no success and since I was here I just asked - my mistake and I'm sorry.
Thanks again for your help,
Dirso
|
|
|
|
|
If you want to be able to change the values X, Y or Z after the instance has been created, you should make it a class. A struct should be immutable, to avoid situations where you would modify a copy of the data that you actually wanted to modify.
A struct is a bit tricker to implement correctly, so until you have read up a bit on the subject you should just stick to classes.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks! Performance could be an issue here, so if struct is faster I'll go for it. about change values I'll try to use "out"/"ref" parameters everytime, right?
Thanks,
Dirso
|
|
|
|
|
Dirso wrote: Performance could be an issue here, so if struct is faster I'll go for it.
If you have an array of the type, a structure uses less memory, which can improve performance a bit. A struct is faster for some operations, but you have to keep it smaller than 16 bytes to be efficient.
Dirso wrote: about change values I'll try to use "out"/"ref" parameters everytime, right?
That doesn't help, as you would still change the vales of a copy, which doesn't affect the original.
A structure should be immutable, i.e. you assign the values when you create the instance, and if you want to change a value you create a new instance. That way the structure instance works as a single value, which is the intention of the structure concept.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|