|
This effect can be fairly easily done.
Use the designer to add some sample text like email address and change the coloer to your light grey color. The designer will look like something lke:
Me.TextBox1.ForeColor = System.Drawing.Color.Silver
Me.TextBox1.Text = "Sample text"
As soon as the user starts to type in the text box you want the text to clear and the color to change. So handle a couple possible events like this:
Private m_bFirst As Boolean = True
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If m_bFirst Then
'clear the text
TextBox1.Text = ""
TextBox1.ForeColor = Color.Black
End If
End Sub
Private Sub TextBox1_MouseDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles TextBox1.MouseDown
If m_bFirst Then
'clear the text
TextBox1.Text = ""
TextBox1.ForeColor = Color.Black
End If
End Sub
I have just made these changes to the form where I was using the text box. If you wanted to use this style more then once you could make a custom control.
|
|
|
|
|
I wanted to avoid wriring but it's not too long to do so let's get busy !
|
|
|
|
|
Hi.
I need to ecncrypt password and store it in DB for later use. How do I do that?
I use System.Security.Cryptography.RijndaelManaged to encrypt password (please see code below). Here's where I'm stack. How do I save it in DB and how do I decrypt it later on as well? I generate IV and key to encrypt password but I'm sure I need to keep them for later use somehow. I will need to decrypt password back when user returns.
Please help.
<br />
Dim original As String = txtPassword.Text<br />
Dim myRijndael As New RijndaelManaged<br />
Dim encrypted() As Byte<br />
<br />
Dim key() As Byte<br />
Dim IV() As Byte<br />
<br />
'Create a new key and initialization vector.<br />
myRijndael.GenerateKey()<br />
myRijndael.GenerateIV()<br />
<br />
'Get the key and IV.<br />
key = myRijndael.Key<br />
IV = myRijndael.IV<br />
<br />
key = myRijndael.Key<br />
IV = myRijndael.IV<br />
<br />
'Get an encryptor.<br />
Dim transform As System.Security.Cryptography.ICryptoTransform<br />
transform = rmcrypto.CreateEncryptor(key, IV)<br />
encrypted = transform.TransformFinalBlock(encoder.GetBytes(original), 0, encoder.GetBytes(original).Length)
|
|
|
|
|
If you create a new key for each time you encrypt a password, you have to store the key along with the encrypted password. Then it's not really any point in encrypting it, is there?
A common way of handling passwords is to not store them at all, but only store a hash code of the password. That way noone can ever decrypt the password. When you need to check the password, you get the hash code of the entered password and compare it to the stored hash code.
The GetHashCode method of the string class is not suitable for long term storage, though. You have to use a consistently defined algorithm, like for example MD5.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks. I kinda thought about it too. Here's what I came up with
Function HashPassword(ByVal password As String) As String<br />
Dim hashedPassword As String<br />
Dim hashProvider As SHA256Managed<br />
Try<br />
Dim passwordBytes() As Byte<br />
Dim hashBytes1() As Byte<br />
Dim hashBytes2() As Byte<br />
passwordBytes = System.Text.Encoding.Unicode.GetBytes(password)<br />
hashProvider = New SHA256Managed<br />
hashProvider.Initialize()<br />
hashBytes1 = hashProvider.ComputeHash(passwordBytes)<br />
hashBytes2 = hashProvider.ComputeHash(hashBytes1)<br />
hashedPassword = Convert.ToBase64String(hashBytes2)<br />
Finally<br />
If Not hashProvider Is Nothing Then<br />
hashProvider.Clear()<br />
hashProvider = Nothing<br />
End If<br />
End Try<br />
Return hashedPassword<br />
End Function
|
|
|
|
|
One way is to specify the key & IV rather than generating them. Then you use the same values to decrypt.
e.g.
myRijndael.Key = keyBytes ' 32 bytes<br />
myRijndael.IV = ivBytes ' 16 bytes
"For fifty bucks I'd put my face in their soup and blow." - George Costanza ~ Web SQL Utility - asp.net app to query Access, SQL server, MySQL. Stores history, favourites.
|
|
|
|
|
I see. Do you have any example of how I can create these?
Can they be random (I mean different)?
Thanks,
|
|
|
|
|
Yep they're different.
One common way is to use the PasswordDeriveBytes class.
E.g. (in C#):
byte[] key = new PasswordDeriveBytes("secret_pass", new byte[]{ 21, 5, 85, 200, 43, 65, 44 }).GetBytes(32);<br />
byte[] iv = new PasswordDeriveBytes("secret_pass", new byte[]{ 21, 5, 85, 200, 43, 65, 44 }).GetBytes(16);
BTW those numbers are random. You can make up your own byte array. It's known as the salt .
"For fifty bucks I'd put my face in their soup and blow." - George Costanza ~ Web SQL Utility - asp.net app to query Access, SQL server, MySQL. Stores history, favourites.
|
|
|
|
|
Thanks man. I look into this. I found one way as you can see in my reply to another guy but would really like to finish what I've started.
Thanks again.
|
|
|
|
|
Hello My Dears............
I have downloaded "Network Sniffer & Connection Analyzer" code but get problem in running the code in "Microsoft Visual Studio 2005 Express Edition".....
PLZ Help me in running this code(Give details for running)..............Thanks.
khalid mahmood
|
|
|
|
|
hazarian wrote: Give details for running
How about giving details of what problem you are having?
|
|
|
|
|
This code consists of three Projects i-e "Port scanner,Sniffer,SnifferUI"......What should be the exact way of running these three projects.
khalid mahmood
|
|
|
|
|
Hi,
I've got a combobox to which I add objects.
I would like to have one specifiec object selected.
Some of the objects contain the same DisplayMember but differ in other aspects = index.
When the objects that do not have dublicates are selected there is no problem in selecting correct item as selected, but when the object has DisplayMember dublicates the first displayed items is always selected no matter what SelectedIndex or SelectedItem is assigned.
Any tip?
ToDo
|
|
|
|
|
I looked at DisplayMember under the ComboBox entry in MSDN for VS2005 and there was an example program (for ListBoxes) which I subtley changed to be a ComboBox. I also modified the sample data to contain duplicate DisplayMember values. It seems to work perfectly as far as I can tell, but maybe I am missing your point?
Just copy and paste all this code into a WindowsApplication.
HTH - Des
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
//private ListBox ListBox1 = new ListBox(); // Just for our test
private ComboBox ListBox1 = new ComboBox();
private TextBox textBox1 = new TextBox();
public Form1()
{
this.ClientSize = new Size(292, 181);
this.Text = "ListBox Sample3";
ListBox1.Location = new Point(24, 16);
ListBox1.Name = "ListBox1";
ListBox1.Size = new Size(232, 130);
textBox1.Location = new Point(24, 160);
textBox1.Name = "textBox1";
textBox1.Size = new Size(240, 24);
this.Controls.AddRange(new Control[] { ListBox1, textBox1 });
// Populates the list box using DataSource.
// DisplayMember is used to display just the long name of each state.
ArrayList USStates = new ArrayList();
USStates.Add(new USState("Alabama", "AL"));
USStates.Add(new USState("Washington", "WA"));
USStates.Add(new USState("Washington", "W1")); // Duplicate DisplayMember
USStates.Add(new USState("West Virginia", "WV"));
USStates.Add(new USState("Wisconsin", "WI")); // Duplicate DisplayMember
USStates.Add(new USState("Wisconsin", "W1"));
USStates.Add(new USState("Wyoming", "WY"));
ListBox1.SelectedValueChanged += new EventHandler(ListBox1_SelectedValueChanged);
ListBox1.DataSource = USStates;
ListBox1.DisplayMember = "LongName";
ListBox1.ValueMember = "ShortName";
}
private void ListBox1_SelectedValueChanged(object sender, EventArgs e)
{
if (ListBox1.SelectedIndex != -1)
textBox1.Text = ListBox1.SelectedValue.ToString();
}
}
public class USState
{
private string myShortName;
private string myLongName;
public USState(string strLongName, string strShortName)
{
this.myShortName = strShortName;
this.myLongName = strLongName;
}
public string ShortName
{
get
{
return myShortName;
}
}
public string LongName
{
get
{
return myLongName;
}
}
public override string ToString()
{
return this.ShortName + " - " + this.LongName;
}
}
}
|
|
|
|
|
Hi,
thanks for the reply.
Try chaning this code part, I get the the first Washington selected.
// Populates the list box using DataSource.
// DisplayMember is used to display just the long name of each state.
ArrayList USStates = new ArrayList();
USState defaultSelection = new USState("Washington", "W1"); //New
USStates.Add(new USState("Alabama", "AL"));
USStates.Add(new USState("Washington", "WA"));
USStates.Add(defaultSelection); // Duplicate DisplayMember //Changed
USStates.Add(new USState("West Virginia", "WV"));
USStates.Add(new USState("Wisconsin", "WI")); // Duplicate DisplayMember
USStates.Add(new USState("Wisconsin", "W1"));
USStates.Add(new USState("Wyoming", "WY"));
ListBox1.SelectedValueChanged += new EventHandler(ListBox1_SelectedValueChanged);
ListBox1.DataSource = USStates;
ListBox1.DisplayMember = "LongName";
ListBox1.ValueMember = "ShortName";
ListBox1.SelectedItem = defaultSelection; //New
Regards,
ToDo
|
|
|
|
|
Now I see what you mean, I originally thought that no matter which of the duplicates you selected, you were only getting the object mapped to the first duplicate returned, but I think what you are saying is that when you go to the ComboBox, the selected object is the first of the duplicates in the list.
I haven't a way around this yet, but at least I now understand the problem.
|
|
|
|
|
Hello,
I'm new to .net 2.0 and have the following problem:
I have multiple tables in a MSSQL database.
I use DataGridViews to display or enter Data to this tables
Visual Studio has put some things automatically in:
DataSet<->BindingSource<->BindingNavigator<->TableAdapter<->DataGridView
I have the problem to find a starting point for doing something. I have added after
InitializeComponent();
a few lines to display the table.
try<br />
{<br />
this.xyzTableAdapter.Fill(this.testDataSet.xyz);<br />
}<br />
catch (System.Exception ex)<br />
{<br />
System.Windows.Forms.MessageBox.Show(ex.Message);<br />
}<br />
this.xyzDataGridView.Columns[0].DefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Italic);<br />
Also I used the SaveItem_Click-event to save the data back to the database
<br />
try<br />
{<br />
this.Validate();<br />
this.xyzBindingSource.EndEdit();<br />
this.xyzTableAdapter.Update(this.testDataSet.xyz);<br />
}<br />
catch (System.Exception ex)<br />
{<br />
MessageBox.Show("Update failed" + ex.ToString());<br />
}<br />
This works, but i don't have a clue if this is the best method of doing this.
That is not the main problem.
What i really want are 2 thing:
I want to combine to tables in one DataFlexGrid.
Example:
One table may be car.
A car could have tires which are in another table.
So table "car" should contain a link to table "tire" as foreign key.
What i want in the DataGridView is a DataGridViewComboBox-column, where a user could just choose the "tire" for the "car" from.
Where I have problems doing this:
I have no starting point.
In the designer i can change the column value to DataGridViewComboBox. But I don't know how to fill the ComboBox (one other thing that i search is how to prefil cells if a new row is added, e.g. adding a new DateTime).
Selects could be written easy (Like SELECT car.carID, car.name, tire.name FROM car, tire WHERE car.tireID = tire.tireID or for the Combobox SELECT tire.name, tire.tireID FROM tire), but I don't know where to put these to.
The second problem would be the other was round: How could i alter the insert so that the tireID would be written to the car table?
Under DataSource "Edit DataSet with Designer" I could enter additional Insert Statements to the tableAdapter. But i have no clue how to use them. Whatever I do, they seem to be ignored.
Can anybody help? If there exists something like a tutorial or HowTo it would also help.
Regards
Wolfgang Schmidt
-- modified at 16:20 Thursday 23rd November, 2006
|
|
|
|
|
Have you found a solution to the problem?
Some people have a memory and an attention span, you should try them out one day. - Jeremy Falcon
|
|
|
|
|
Yes, I did not find the data source properties for the dropdown the first time. Wanted to do it manually, but it is also fine using the designer
|
|
|
|
|
hi is there any way to run a batch file from c# application
hello
|
|
|
|
|
Hi,
you can launch all kinds of commands, including opening Word documents, or executing
DOS batch files, using the Process and StartInfo classes.
Put the batch file name into StartInfo.FileName, and optional arguments in StartInfo.Arguments.
Luc Pattyn
|
|
|
|
|
Does anyone have any links to resources that may help me. I've been asked to come up with a proposal for an intercom type system, LAN based only.
The problem over normal VOIP is that the voice communication is a simulation of radio traffic, so the users on system may all be on different channels, only when connected to the same channel can they communicate.
To simplify, I'm willing to have a limited number of preset channels which users can join/leave. When two or more people are on the same channel, they can talk to each other in a half-duplex method.
I was thinking about having a "server" machine and using some form of remoting allowing users to call a common Talk() method on a remote instance (thus allowing the blocking others from talking if required).
My questions really are related to the "streaming" of the transmit from the "talker" out to the "listener".
I should have time to do a good implementation, but need to present the posposal at the start of next week!
Any links, ideas would be welcome.
Regards,
Ray
|
|
|
|
|
Convinced there are good products out there! and probabely very cheap
|
|
|
|
|
~~~Johnny~~~ wrote: Convinced there are good products out there! and probabely very cheap
I'd love it if there were... and money isn't that big an object for the right product (it's an important component of an 8 figure project).
The latest spanner added to the design is that listeners need to be able to listen to multiple independant channels at the same time! I'm convinved we'll end up creating the framework but I'd still love an API/library to do the comms/audio side of things!
In the mean time, I'm presenting the solution without going into programming/implementation specifics -- since that is actually inappropriate at this early stage of my project!
Regards,
Ray
|
|
|
|
|
hi
Is there any way that we could shut down and restart our system through our c# applicaiotn ? thanks in advance
hello
|
|
|
|
|