|
I dont want to add the string as a resource, but reference the resource from a string.
So if I want to play the resource: Properties.Resources.mysound;, I want the string sent to the function to represent mysound.
|
|
|
|
|
I still don't understand. If you want to play the resource Properties.Resources.mysound, you'll need to convert it to a stream or file and use System.Media.SoundPlayer to play the sound.
You said "I want the string sent to the function to represent mysound". Can you clarify that? What string? What function?
|
|
|
|
|
I have an unmanaged C++ DLL which has the following structures,
typedef struct {char str[200]; } MYARRAY1;
typedef struct {MYARRAY1 myarray1struct;} MYARRAY2;
typedef struct {MYARRAY2 myarray1struct[5];} MYARRAY3;
To return MYARRAY2, I used the following entry function,
extern "C" __declspec(dllexport) void CallTestArray2( MYARRAY2 *pStruct)
To return MYARRAY3, I used the following entry function,
extern "C" __declspec(dllexport) void CallTestArray3( MYARRAY3 *pStruct)
In C#, I declared the following structures,
[StructLayout(LayoutKind.Sequential)]
public struct MyArray1
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=200)] public String str;
}
[StructLayout(LayoutKind.Sequential)]
public struct MyArray2
{
public MyArray1 tempArray1;
}
[StructLayout(LayoutKind.Sequential)]
public struct MyArray3
{
public MyArray2[] tempArray2;
}
I do not have any problem using DLLImport call to C++ DLL to get data in MyArray2, however when I try to get data in MyArray3 with the following code, all data in testArray3 are empty.
MyArray3 testArray3 = new MyArray3();
testArray3.tempArray2 = new MyArray2[ 5 ];
CallTestArray3(ref testArray3);
Any help is appreciated!!!
|
|
|
|
|
vitowong wrote: [StructLayout(LayoutKind.Sequential)]
public struct MyArray3
{
public MyArray2[] tempArray2;
}
Underlined should be also marshaled.
|
|
|
|
|
MyArray2 is based on MyArray1, and MyArray1 has been marshaled. Is it need for MyArray2[] be marshaled? I tried to marshal as AsAny, but it doesn't work. What do I be marshal as? Thanks.
|
|
|
|
|
I am building an application that must take one Dataset table apart and display it in two different DataGridView's along with one additional field from a second table.
I'm iterating through the transactions and building out a DataTable for each set of records. (this part works nicely) Then set my grids as follows:
payView.DataSource = new DataGridView( payData );
refView.DataSource = new DataGridView( refData );
So far so good, everything works...almost. I have one column defined as a DataGridViewCheckboxCell and that column is not bound to any data. The remaining columns ARE bound to my fields in my data tables and all of them are readonly. My DataGridViewCheckboxCell is marked as ReadOnly=false and I even tried marking my DataGridView as ReadOnly=false. All to no avail. If I click on it, the cell never changes value and remains unchecked. Here is my column definition:
this.selected1 = new DataGridViewCheckBoxColumn();
this.selected1.ReadOnly = false;
this.selected1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.selected1.HeaderText = "Sel";
this.selected1.Name = "paymentSelect";
this.selected1.Resizable = System.Windows.Forms.DataGridViewTriState.False;
Finally I wanted to highly a cell that fell outside the allowed parameters. The logic works well. The cell is identified and the cell.Style was set to a new highlightedStyle object with a light red background color. However the DataGridView never changes the background painting. The only way I got it to work is by hooking into the RowPrePaintEvent and setting the background color there. Why is it working like this??? Why is this control being so difficult to work with????
Any help in getting the checkbox to function properly would be greatly appreciated.
|
|
|
|
|
Unbound CheckBoxColumn works fine here, just click Colums property of the DataGridView in the designer, add the unbound column, and voila, perfectly editable. Here's the designer generated code:
private void InitializeComponent() {<br />
this.dataGridView1 = new System.Windows.Forms.DataGridView();<br />
this.Column1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();<br />
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();<br />
this.SuspendLayout();<br />
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;<br />
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {<br />
this.Column1});<br />
this.dataGridView1.Location = new System.Drawing.Point(-4, -1);<br />
this.dataGridView1.Name = "dataGridView1";<br />
this.dataGridView1.Size = new System.Drawing.Size(297, 271);<br />
this.dataGridView1.TabIndex = 0;<br />
this.Column1.HeaderText = "Column1";<br />
this.Column1.Name = "Column1";<br />
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);<br />
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;<br />
this.ClientSize = new System.Drawing.Size(292, 268);<br />
this.Controls.Add(this.dataGridView1);<br />
this.Name = "Form1";<br />
this.Text = "Form1";<br />
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();<br />
this.ResumeLayout(false);<br />
}<br />
Wout
|
|
|
|
|
Yes, well I'm not build the columns in the designer. I'm building them in code.
|
|
|
|
|
The designer writes code, and I showed the working generated code... So it should work too if you type this manually if you prefer that.
Wout
|
|
|
|
|
Hello ...
I would like to create a sample messagbox which suppoted the
visual style office 2003.
I create a UserControl which inherits from
system.Windows.Forms.MessageBox (override paint method) ...
unfortunly I can`t intherits from messagebox!
Please tell me what I have to done to get a MessagBox which
supports the Office 2003 style.
best regards....
|
|
|
|
|
Just create a form which inherits from user control, slap your a label, image, and buttons on there and you're good to go. A MessageBox is just a type of form, after all.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
What's the proper way of overriding Dispose(bool disposing); in a UI control? The method is already overridden in the designer generated file in .NET 2.0. I never edit that file manually, so how are you supposed to override it then? Or is the proper way to add stuff to the components field, which gets cleaned up by the Dispose method? Then I have to make the disposable objects IComponent objects, slightly more work then I'd like to do.
Wout
|
|
|
|
|
// an example of the IDispose pattern
private System.ComponentModel.IContainer components = null;
public void Dispose()
{
this.Dispose(true);
}
protected internal void Dispose(bool disposing)
{
if ( disposing && components != null )
components.Dispose();
base.Dispose(disposing);
}
|
|
|
|
|
Yes yes, I'm not a moron. I'm wondering how I'm supposed to override the ALREADY OVERRIDDEN Dispose method present in the designer generated file, without touching that file.
Sorry, I'm not angry.
Wout
|
|
|
|
|
Quote: What's the proper way of overriding Dispose(bool disposing); in a UI control? :EndQuote
I answered what you asked.
If the Dispose method is already overriden and not made virtual, then you cannot override it.
|
|
|
|
|
You overlooked the "overriding" part?
My first feeling is too that I can't override without touching the designer file. That would be utterly stupid, and I can't believe that. So there must be a way of hooking into the Dispose... Maybe I should add the disposable part to the components field, at least that works.
Wout
|
|
|
|
|
Hi guys,
I am a newbie in C# and I need some help. If I open a database connection in my try statement, can I close it in finally. i.e. is finally always executed?
This is what I have; is this a good programming technique?
Please help
public int validateGLAccount(string Number)
{
//bool rt=true;
SqlConnection cnn=null;
SqlCommand cmd=null;
try
{
cnn=new SqlConnection(m_Cnn);
cnn.Open();
if (true)
{
cmd= new SqlCommand("SELECT count(ID) FROM table",cnn);
one = (int)cmd.ExecuteScalar();
if (one==1)
{
return -1;
}
else
{
return 1;
}
}
else
{
return -1;
}
}
catch(Exception ex)
{
MessageBox.Show(this,ex.Message);
}
finally
{
cmd=null;
if(cnn!=null && cnn.State !=ConnectionState.Closed)
{
cnn.Close();
}
cnn=null;
}
return -1;
}
sasa
|
|
|
|
|
Looks great. Even easier is doing:
using (SqlConnection connection = new SqlConnection(m_ConnectionString)) {
}
This is just some c# convenience for try {} finally { connection.Dispose(); }
Wout
|
|
|
|
|
Thank you for your response. I appreciate it.
sasa
|
|
|
|
|
SASA_1 wrote: I am a newbie in C# and I need some help. If I open a database connection in my try statement, can I close it in finally. i.e. is finally always executed?
Yes - the code in finally is always executed.
I'm new myself so won't comment on the code - if it works then it's fine Worry about perfection in a few months time!
Glen Harvy
|
|
|
|
|
Hi,
i need to translate a c# webcontrol in asp code.
For example:
Button b = new Button();
to
<asp:button id="Button1" runat="server" Text="Button"></asp:button>
I would pre-generate aspx page that can be modified in Visual Studio 2005.
Thank You
BDN
|
|
|
|
|
The combo box is usually used to select a value from a predefined list to insert into another object. So, in general we bind the ComboBox to the list of values and get the SelectedValue for updating.
My question is this: is there a simple way for the ComboBox to updates its own values when a user types values?
My ComboBox is bound to a three column data table and in my wildest dreams I'd like for the user to type a value and the datatable updates the value previiously selected instead of moving the SelectedIndex to -1.
I didn't find any example of this anywhere.
Thanks in advance.
|
|
|
|
|
Are you working in WinForms or ASP.NET? It makes a world of difference.
|
|
|
|
|
Sorry, important detail, I work in WinForms
|
|
|
|
|
The program I’m working on allows the user to produce a number of pictureboxes, set their pictures and drag them around. I also needed to store extra information about each picturebox, so I created a class called ‘item’ that has values such as ‘previousx’ ‘previousy’ etc. At the moment I have an ‘item’ for each picturebox, and all the ‘items’ in a collection so that when the user starts working with a different picturebox, the program has to look through the collection to find the correct item, so it can display the correct variables.
However, I realised that the Tag property of each picturebox can take an object, not just a single string or int etc. So attaching each picturebox’s item class to its tag should be more efficient and easier to work with. My problem is, how do I go about accessing the variables once they are stored in the tag. For example,
x = pictureBox1.Tag.previousx
would give an error on compile, as the property does not exist at build time. Is there any way to get this to work?
Thanks for the help.
|
|
|
|