|
can you rephrase your question ?
Shardool Karnik
Lead Software Engineer
Compass Technologies, Inc.
http://www.compasstec.com
|
|
|
|
|
You have to cast the reference:
DateTimePicker dtp = ctl as DateTimePicker;
DateTime value = DateTime.MinValue;
if(dtp != null)
{
value = dtp.Value;
}
else
{
} I hope this helps!!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
(New C# user here)
I have a binary registry value (an encoded password) that I need to retrieve and pass as a string to the decoder.
The (example) registry value is:
01 00 02 00 03 00 00 00
What I need to end up with is a string with the bytes in each char reversed like in this hex literal:
"\x0001\x0002\x0003\x0000"
RegistryKey.GetValue("MyValue").ToString() does not do the 'endian conversion on each char that I need. (In fact, I can't really tell what it's doing! Probably some fancy stuff related to locale...)
How can I get at this binary registry value as an array of bytes and then convert it to my desired string?
Thanks!
--
Ray Marron
|
|
|
|
|
I figured it out:
<br />
string sPass = "";<br />
object oPass = rk.GetValue("Password", null);<br />
if (oPass != null) <br />
{<br />
byte[] aPass = (byte[])oPass;<br />
int i, j;<br />
for (i = 0; i < aPass.Length; i += 2)<br />
{<br />
j = aPass[i] + (aPass[i + 1] * 256);<br />
sPass += (char)j;<br />
}<br />
}<br />
|
|
|
|
|
Hi all,
My application loads user selected images in Imagelist for thumbnail display in Listview...Here's the code that i use do that..
ImageList.Images.Add(imageToLoad,Image.FromFile(imageToLoad));<br />
LstVwImage.Items.Add(imageToLoad,imageToLoad);
So far so good, When user selects any image from listview and selects Delete button, I want it to remove items from listview and imagelist and delete physical file corrosponding that path, here's the code I am using...
<br />
LstVwImage.Items.RemoveAt(deleteIndex);<br />
ImageList.Images.RemoveAt(deleteIndex);<br />
FileInfo fi = new FileInfo(deleteFile);<br />
fi.Delete();<br />
Unfortunately its not able to delete file, saying "File is being used by another process"...Its not permission error as I am able to delete any file if its not loaded in imagelist or listview...
Either I'm getting crazy or stupid error!!!
Pls throw some light on this!!
Regards
MaulikCE
"Every obstacle presents an opportunity to improve our condition."
|
|
|
|
|
I guess it is that the image hasn't been garbage collected yet, so the image file isn't closed..
You should try to call the Dispose method of the image before the delete function is called..
|
|
|
|
|
I'm still fairly low on the C# learning curve, especially with respect to WinForms. I've been searching all over the place for a suitable answer to my requirement, so far to no avail. Time to beg here.
Consider a typical 2-column ListView. When you select one of the rows, I want the item in Column 2 to turn into a DropDown to allow selection from a fixed list. The unselected rows simply show the text previously selected from the dropdown.
So far I've found hints that I'll need to do some sort of subclassing of the ListView, but nothing further. A code sample would be outstanding if possible. In fact, I see this as the kind of thing that'd make a good CodeProject article.
Thanks in advance for any advice.
Brad.
|
|
|
|
|
b_p_smith wrote:
I see this as the kind of thing that'd make a good CodeProject article.
You bet! It's not easy at all what you're trying to accomplish. The ListView has a GetItemRect method to get the rectangle of the item (the selected item), but not for a specific subitem, so you would have to get the width of each column from the Columns collection.
And, what happens if all the columns are wider that the control? and if the ComboBox is in a column scrolled out (horizontally)? Or if the selected item is scrolled out of view (vertically)?
You have the EnsureVisible method, but not something that will tell you if the item is visible or not.
[EDIT: I know I didn't solve your problem, but I hope to have given you a few pointers at least.]
Good luck!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Thanks. I've noted all that. In my case, I can take steps (or at least try to) that'll ensure the column of interest is visible. But you make some good points that I'll have to keep in mind.
Brad.
|
|
|
|
|
|
That looks like it might just do the trick. For some reason I thought there'd be a solution that involved a little less "trickery", but whatever works.
I'll poke at this today.
Brad.
|
|
|
|
|
I have an API I'm wrapping in C#, and I'm having trouble tweaking the DllImport.
Here's the struct definition in C#:
[
MarshalAs(
UnmanagedType.Struct,
SizeConst = 512,
CharSet = CharSet.Ansi
)
]
public struct MyStruct
{
[MarshalAs(UnmanagedType.I4)]public Int32 Size;
[MarshalAs(UnmanagedType.LPStr, SizeConst = 508)]public String Name;
}
In C:
public struct MyStruct
{
int size,
char[508] name
}
And the C function declaration:
EXPORT void ListFiles(void* buffer, DWORD count)
{
}
The idea is to pass in a pointer to a buffer. The API function will fill that buffer with count records. Each record being byte data in the format of MyStruct .
I can successfully retrieve the data by passing in a buffer of type byte[512 * count] . But then I have to manually parse the data with BitConverter calls in a for loop.
What I'm trying to do is declare an array of MyStruct[count] , and set up a DllImport that will properly marshal that array into the API, so that the API can fill the structures directly, with no need for me to parse data on return.
I've had no success with this whatsoever using MarshalAs(UnmanagedType.LPArray) or trying to let the compiler do automatic marshalling. Everything I've tried results in an array of structures that all have size 0 and null names.
Anyone have any pointers or suggestions to help me figure out how to marshal an array of structs from C# as a void* in C++?
Grim (aka Toby) MCDBA, MCSD, MCP+SB
SELECT * FROM users WHERE clue IS NOT NULL
GO
(0 row(s) affected)
|
|
|
|
|
Although I don't know the answer, I may have a tip to you: I learned that, for some more complicated cases, a managed C++ wrapper is the way to go. Interop coding that takes hours or days of coding in C# often takes only a few minutes in managed C++.
Unless you have a strong reason to stay with "pure C#", I'd consider using managed C++.
I see dead pixels
Yes, even I am blogging now!
|
|
|
|
|
I know that this is extremely simple. I want to display the text of a textBox on one form on the text of a label on another form. The code that I have works, but what gets displayed on form2.label is the text of form1.textBox at Design Time. Here is what I got.
/// Code on the first form.
private void button1_Click(object sender, System.EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}
/// Code on the second form.
private void button1_Click(object sender, System.EventArgs e)
{
Form1 form1 = new Form1();
label1.Text = form1.textBox1.Text;
}
|
|
|
|
|
put a function in form2 to get your value, and then call it from form1. Set your label there.
Have a wonderful evening
Doug Wright
Developer, TDCI
|
|
|
|
|
kornstyle wrote:
private void button1_Click(object sender, System.EventArgs e)
{
Form1 form1 = new Form1();
label1.Text = form1.textBox1.Text;
}
You are creating a new form everytime you try to get the text (but you never make it visible). That's why you get the text set at design time.
You need to somehow get a reference to the existing Form1 .
private void button1_Click(object sender, System.EventArgs e)
{
Form2 form2 = new Form2(this);
form2.Show();
}
Form _form1 = null;
public Form2(Form form1)
{
_form1 = form1;
}
private void button1_Click(object sender, System.EventArgs e)
{
label1.Text = _form1.textBox1.Text;
}
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
|
Hi, need some help about this
I want to convert a string to a DateTime, which isn't too hard but I want empty strings to become DateTime.MinValue (to represent DBNull).
The question is if this can be done by a custom format provider so i can use it like:
Convert.ToDateTime(dateString, myFormatProvider);
Thanks in advance
|
|
|
|
|
I would write a helper routine:
DateTime ConvertFromString(string s)
{
if(s == "")
return DateTime.MinValue;
else
return Convert.ToDateTime(s);
} Good luck!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I have the window handle of another window (found it using findwindow)
Now I need to find that windows state.. ie. is it minimized or not?
I've spent ages messing with Getwindowlong, but i cant make anything of it. Can anyone help me out?
|
|
|
|
|
Are you trying to inter-op on GetWindowLong ? Hmm...
There is a static method Control.FromHandle that will return a Control object of the window handle. Because I'm paranoid, I would use Control.TopLevelControl which is a better shot at getting something that is Form object. If you can get the Form you can call Form.WindowState which will indicate if it is minimized, maximized, or normal.
At least I guess it would. I have never tried doing this on handle that is outside of the application.
|
|
|
|
|
cheers, ill try it out when ive got a spare hour or so
|
|
|
|
|
Hi
I extended a textbox control and created a property i.e
public enum myVarEnum {Apple,Mango,Peach};
protected myVarEnum myvar1;
public myVar MyProperty
{
get { return myvar1; }
set { myvar1 = value; }
}
Now when i use this extended control i am getting the property as a dropdown and i am able to select, the problem is the value i select doesnot persist..for example if i select "Mango" it goes back to the first one "Apple" after i build the solution. i guess its a small mistake plz help me overcome this...
Regards
Deepak.S
|
|
|
|
|
Hi!
Is there any elegant (and fast, have to run across >100MB of text!) way to perform a case-insensitive string replace?
String or StringBuilder don't allow me to specify the type of comparison (case sensitive or not) in their Replace() methods, with RegEx I can run into problems when the search string contains characters with special meaning in regular expressions.
Any pearls of wisdom?
TIA,
mav
|
|
|
|
|
Hello, can anyone help me with this ?
I have an Arraylist filled with User-objects (containing name and account info).
lstSource.DataSource = personList;<br />
lstSource.DataTextField = "firstName";<br />
lstSource.DataBind();
This works nice: see screenshot[^]
Now comes the problem, how do I retrieve the objects that I placed in the listbox? I mean something like:
user person = lstSource.SelectedItem;<br />
string name = person.Firstname;
or
user person = (user)lstSource.SelectedItem;<br />
string name = person.Firstname;
|
|
|
|