|
Thanks I figured out what I was doing wrong thanks for the input
|
|
|
|
|
help , i need to make a tic tac toe game using control arrays
please help
|
|
|
|
|
Check the information from kidwaresoftware lesson[^]. I forget that tic-tac-toe in which chapter. Try to browse it by yourself.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
Hi,
I am strugling with the propertygrid and a listbox. I am using the
universaldropdowneditor from the codeproject (code below). However I am
populating the listbox via a datasource. The problem I am having is that when
I have a value in the propertygird and edit that, I want the listbox to have
the selectvalue equal to the value that is being edited. Just to make it
clearer:
PropgridVal = Germany
Datasource=
Belgium
France
Italie
Germany
Currently when I edit a value it defaults directly to Belgium, instead of
Germany
I do not understand, when I use listbox.selectedvalue="Germany" the
selectedvalue remains Nothing
please help
David J
Thankks
David J
#Region " UniversalDropdownEditor class "
Public Class UniversalDropdownEditor
Inherits UITypeEditor
Private edSvc As IWindowsFormsEditorService
Private valMemb As ValueMemberAttribute
Public Overloads Overrides Function GetEditStyle(ByVal context As _
ITypeDescriptorContext) As UITypeEditorEditStyle
If Not context Is Nothing AndAlso Not context.Instance Is Nothing Then
Return UITypeEditorEditStyle.DropDown
End If
Return UITypeEditorEditStyle.None
End Function
<refreshproperties(refreshproperties.all)> _
Public Overloads Overrides Function EditValue( _
ByVal context As ITypeDescriptorContext, _
ByVal provider As System.IServiceProvider, _
ByVal value As [Object]) As [Object]
If context Is Nothing OrElse provider Is Nothing _
OrElse context.Instance Is Nothing Then
Return MyBase.EditValue(provider, value)
End If
' Dim att As SourceCollectionAttribute = _
' context.PropertyDescriptor.Attributes( _
' GetType(SourceCollectionAttribute))
'If att Is Nothing Then
' nothing we can do here
'Return MyBase.EditValue(provider, value)
'End If
Me.edSvc = provider.GetService(GetType(IWindowsFormsEditorService))
'If Me.edSvc Is Nothing Then
' nothing we can do here either
'Return MyBase.EditValue(provider, value)
'End If
'prepare the listbox
Dim lst As New ListBox()
Me.PrepareListBox(lst, context)
If Me.valMemb Is Nothing Then
lst.SelectedItem = value
Else
Me.valMemb.SelectByValue(lst, value)
End If
Me.switchloaded = False
Me.edSvc.DropDownControl(lst)
Me.switchloaded = True
' we're back
If lst.SelectedItem Is Nothing Then
value = Nothing
Else
value = lst.Text
'Else
' value = Me.valMemb.GetValue(lst)
End If
Return value
End Function
Private Sub PrepareListBox(ByVal lst As ListBox, _
ByVal context As ITypeDescriptorContext)
Dim SysSetTypeAttr As PropertySysSetTypeAttribute =
context.PropertyDescriptor.Attributes(GetType(PropertySysSetTypeAttribute))
Dim syssetType As Short = SysSetTypeAttr.PropertySysSetTypeAttribute
lst.IntegralHeight = True ' resize to avoid partial items
Dim coll As DataTable =
funGetPropVal(context.PropertyDescriptor.Name, SysSetType)
If lst.ItemHeight > 0 Then
Dim adjHei As Integer = (coll.Rows.Count + 1) * lst.ItemHeight
If Not coll Is Nothing AndAlso _
lst.Height / lst.ItemHeight < coll.Rows.Count Then
' try to keep the listbox small but sufficient
If adjHei > 200 Then adjHei = 200
End If
lst.Height = adjHei
Else ' safeguard, although it shouldn't happen
lst.Height = lst.ItemHeight
End If
lst.Sorted = True ' present in alphabetical order
FillListBoxFromCollection(lst, coll)
Me.AssignValueMember(lst, context.PropertyDescriptor)
Me.AssignDisplayMember(lst, context.PropertyDescriptor)
' attach event handler
AddHandler lst.SelectedIndexChanged, AddressOf Me.handleSelection
AddHandler lst.DoubleClick, AddressOf Me.handledoubleclick
End Sub
Public Shared Sub FillListBoxFromCollection(ByVal lb As ListBox, ByVal
coll As DataTable)
Dim DataRowX As DataRow
' prevent flickers and slow downs by entering the mass update mode
lb.BeginUpdate()
lb.Items.Clear()
lb.MultiColumn = False
Dim intCount As Integer
lb.DataSource = coll
lb.Invalidate()
End Sub
Private Sub AssignValueMember(ByVal lc As ListControl, ByVal pd As
PropertyDescriptor)
Dim Attr As ValueMemberAttribute = New ValueMemberAttribute("Name")
Me.valMemb = Attr 'pd.Attributes(GetType(ValueMemberAttribute))
lc.ValueMember = Me.valMemb.ValuePropertyName
End Sub
Private Sub AssignDisplayMember(ByVal lc As ListControl, ByVal pd As
PropertyDescriptor)
Dim att As DisplayMemberAttribute = New DisplayMemberAttribute("Name")
If att Is Nothing Then Return
lc.DisplayMember = att.DisplayPropertyName
End Sub
Private Sub handleSelection(ByVal sender As Object, ByVal e As EventArgs)
If Me.edSvc Is Nothing Then Return
If Me.switchloaded = False Then Return
Me.edSvc.CloseDropDown()
End Sub
Private Sub handledoubleclick(ByVal sender As Object, ByVal e As
EventArgs)
If Me.edSvc Is Nothing Then Return
Me.edSvc.CloseDropDown()
End Sub
End Class
#End Region
#Region " Attributes "
#Region " Auxiliary attribute that fetches the specified source collection "
<description("service attribute="" to="" point="" the="" source="" collection."),="" _=""
="" attributeusage(attributetargets.all)=""> _
Public Class SourceCollectionAttribute
Inherits Attribute
Private srcCollName As String
Public ReadOnly Property CollectionName() As String
Get
Return Me.srcCollName
End Get
End Property
Public ReadOnly Property Collection(ByVal instance As Object) As
ICollection
Get
Dim pdc As PropertyDescriptorCollection = _
TypeDescriptor.GetProperties(instance)
Dim pd As PropertyDescriptor
For Each pd In pdc
If pd.Name = Me.srcCollName Then
Return pd.GetValue(instance)
End If
Next
Return Nothing
End Get
End Property
Public Sub New(ByVal sourceCollectionPropertyName As String)
Me.srcCollName = sourceCollectionPropertyName
End Sub
End Class
#End Region
#Region " 'Value member' attribute "
<attributeusage(attributetargets.all)> _
Public Class ValueMemberAttribute
Inherits Attribute
Private valMemb As String
<description("the name="" of="" the="" property="" used="" as="" value="" member="" by=""
dynamic="" combo="" type="" editor.")=""> _
Public ReadOnly Property ValuePropertyName() As String
Get
Return Me.valMemb
End Get
End Property
Public Sub SelectByValue(ByVal lb As ListBox, ByVal val As Object)
lb.SelectedItem = Nothing
Dim item As Object
If Not val Is Nothing Then
For Each item In lb.Items
If Me.GetValue(item) = val Then
lb.SelectedItem = item
Exit Sub
End If
Next
End If
End Sub
Public Function GetValue(ByVal obj As Object) As Object
If Me.valMemb = String.Empty Then Return obj
' Dim pi As System.Reflection.PropertyInfo =
obj.GetType().GetProperty("Row")
Dim pi As String = obj.text
If pi Is Nothing Then Return obj
Return pi
End Function
Public Sub New(ByVal valueMemberPropertyName As String)
Me.valMemb = valueMemberPropertyName
End Sub
End Class
#End Region
#Region " 'Display member' attribute "
<attributeusage(attributetargets.all)> _
Public Class DisplayMemberAttribute
Inherits Attribute
Private dispMemb As String
<description("the property="" displayed="" in="" the="" list="" control="" used="" by=""
dynamic="" combo="" editor.")=""> _
Public ReadOnly Property DisplayPropertyName() As String
Get
Return Me.dispMemb
End Get
End Property
Public Sub New(ByVal displayMemberPropertyName As String)
Me.dispMemb = displayMemberPropertyName
End Sub
End Class
|
|
|
|
|
Dim lIndex As Long
lIndex = ListBox1.Items.IndexOf("Germany")
ListBox1.SelectedIndex = lIndex
Many Thanks
Harry
|
|
|
|
|
Ok, I've had an Encrypt / Decrypt routine for a year now, but now I'm wondering if I am missing something in it.
It seems that anyone with different Languages installed on their PC, the Decrypt cannot decrypt data on a PC with standard English. So, how can I enable my encryption routine to handle Locales?? I know that I need to convert the String into Locale specific data, but I am not sure where in this code.
Any help is appreciated.
Public Class ICrypto
'<<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>>
#Region "Methods"
'Function to Return a Key
<DebuggerStepThrough()> _
Private Shared Function GetKey(ByVal Data As String, ByVal KeySize As Integer) As Byte()
Dim nSize As Integer = CInt((KeySize / 8) - 1)
Dim vKey(nSize) As Byte
If (Data.Length >= 1) Then
Dim lastBound As Integer = Data.Length
If (lastBound > nSize) Then lastBound = nSize
For i As Integer = 0 To lastBound - 1
vKey(i) = Convert.ToByte(Data.Chars(i))
Next
End If
Return vKey
End Function
'Function to Get the Initialization Vector
<DebuggerStepThrough()> _
Private Shared Function GetIV(ByVal Data As String, ByVal BlockSize As Integer) As Byte()
Dim nSize As Integer = CInt((BlockSize / 8) - 1)
Dim vVector(nSize) As Byte
If (Data.Length >= 1) Then
Dim lastBound As Integer = Data.Length
If (lastBound > nSize) Then lastBound = nSize
For i As Integer = 0 To lastBound - 1
vVector(i) = Convert.ToByte(Data.Chars(i))
Next
End If
Return vVector
End Function
'Function to Encrypt Data
<DebuggerStepThrough()> _
Public Shared Function Encrypt(ByVal Data As String, ByVal Password As String, Optional ByVal ConvertToBase64 As Boolean = True) As String
Dim provCrypto As Cryptography.SymmetricAlgorithm
Dim mEncryptor As ICryptoTransform
Dim stCrypto As Cryptography.CryptoStream
Dim stMemory As IO.MemoryStream, stWriter As IO.StreamWriter
Dim vData() As Byte
Dim sData As String
'Exit if there is no Data
If (IsNothing(Data)) Then Return String.Empty
If (Data.Equals(String.Empty)) Then Return String.Empty
Try
'Initialize the Crypto Provider (3DES)
provCrypto = Cryptography.TripleDES.Create()
provCrypto.KeySize = 128
provCrypto.BlockSize = 64
provCrypto.Mode = CipherMode.CBC
provCrypto.Padding = PaddingMode.PKCS7
'Initialize the Memory Stream and Encrypt the Data
vData = ConvertStringToBytes(Data)
stMemory = New IO.MemoryStream
mEncryptor = provCrypto.CreateEncryptor(GetKey(Password, provCrypto.KeySize), GetIV("Initialization Vector", provCrypto.BlockSize))
stCrypto = New CryptoStream(stMemory, mEncryptor, CryptoStreamMode.Write)
'Write the Encrypted Data
stCrypto.Write(vData, 0, vData.Length)
stCrypto.FlushFinalBlock()
If (ConvertToBase64) Then
'Base64 Encoding enables Saving to XML
sData = System.Convert.ToBase64String(stMemory.ToArray())
Else
sData = ConvertBytesToString(stMemory.ToArray()) 'Encode the Byte Array to UTF8
End If
Catch ex As Exception ': MsgBox(ex.ToString)
Finally
Erase vData
If (Not IsNothing(stMemory)) Then stMemory.Close() : stMemory = Nothing
If (Not IsNothing(stCrypto)) Then stCrypto.Clear() : stCrypto.Close() : stCrypto = Nothing
If (Not IsNothing(mEncryptor)) Then mEncryptor.Dispose() : mEncryptor = Nothing
If (Not IsNothing(provCrypto)) Then provCrypto.Clear() : provCrypto = Nothing
End Try
'Return the Data
Return sData
End Function
'Function to Decrypt Data
<DebuggerStepThrough()> _
Public Shared Function Decrypt(ByVal Data As String, ByVal Password As String, Optional ByVal ConvertFromBase64 As Boolean = True) As String
Dim provCrypto As Cryptography.SymmetricAlgorithm
Dim mDecryptor As ICryptoTransform
Dim stCrypto As Cryptography.CryptoStream
Dim stMemory As IO.MemoryStream
Dim vData() As Byte
Dim sData As String
'Exit if there is no Data
If (IsNothing(Data)) Then Return String.Empty
If (Data.Equals(String.Empty)) Then Return String.Empty
Try
'Initialize the Crypto Provider (3DES)
provCrypto = Cryptography.TripleDES.Create()
provCrypto.KeySize = 128
provCrypto.BlockSize = 64
provCrypto.Mode = CipherMode.CBC
provCrypto.Padding = PaddingMode.PKCS7
'Decrypt the Data
If (ConvertFromBase64) Then
ReDim vData(Data.Length)
vData = System.Convert.FromBase64String(Data)
Else
vData = ConvertStringToBytes(Data)
End If
stMemory = New IO.MemoryStream
mDecryptor = provCrypto.CreateDecryptor(GetKey(Password, provCrypto.KeySize), GetIV("Initialization Vector", provCrypto.BlockSize))
stCrypto = New CryptoStream(stMemory, mDecryptor, CryptoStreamMode.Write)
stCrypto.Write(vData, 0, vData.Length)
stCrypto.FlushFinalBlock()
'Read the Encrypted Data
sData = ConvertBytesToString(stMemory.ToArray())
Catch ex As Exception ': MsgBox(ex.ToString)
Finally
Erase vData
If (Not IsNothing(stMemory)) Then stMemory.Close() : stMemory = Nothing
If (Not IsNothing(stCrypto)) Then stCrypto.Clear() : stCrypto = Nothing
If (Not IsNothing(mDecryptor)) Then mDecryptor.Dispose() : mDecryptor = Nothing
If (Not IsNothing(provCrypto)) Then provCrypto.Clear() : provCrypto = Nothing
End Try
'Return the Data
Return sData
End Function
'Function to Convert a String to a Byte Array
<DebuggerStepThrough()> _
Public Shared Function ConvertStringToBytes(ByVal Data As String) As Byte()
Return System.Text.UTF8Encoding.UTF8.GetBytes(Data)
End Function
'Function to Convert Bytes to a String
<DebuggerStepThrough()> _
Public Shared Function ConvertBytesToString(ByVal Bytes() As Byte) As String
Return System.Text.UTF8Encoding.UTF8.GetString(Bytes)
End Function
#End Region
'<<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>>
'<<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>>
#Region "Class Constructors / Destructors"
'Initialize the Class
Private Sub New()
End Sub
#End Region
'<<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>><<o>>
End Class
|
|
|
|
|
System.Globalization.CultureInfo
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationcultureinfoclasstopic.asp
|
|
|
|
|
Ok, well I knew I needed the CultureInfo Class...but I have no idea how to go about using it!
I guess I will try to create an InvariantCulture and set it to the Current Culture of the Thread. I will save the existing Culture first so I can restore it later.
Does anyone have an example of this?
|
|
|
|
|
Look here in section 3.3
http://www.gotdotnet.com/team/vb/VBSampleGuidelines.htm
|
|
|
|
|
and here is another reference
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcustomcasemappingssortingrules.asp
|
|
|
|
|
Hi, i need to do an application where i need to have a map and in the map when a click i have to show where is clicked(with a circle or other think) and i neede to save that for printing
thanks
|
|
|
|
|
in the form of a question please...
-jim
|
|
|
|
|
Are you asking how to write a GIS (Geographical Information System) or do you want to buy in a ready made component?
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
more or less... only a map where a can mark something......
Thanks for the reply
|
|
|
|
|
Dear guys
there is a question, i could not know the reason that when i uses RunSQL from VBA in MSAccess to insert or update any record then
if the month figure is greater then day figure then it is saved in reverse order.
I mean that when i want to insert 05-10-2004 as dd-mm-yyyy it is saved as 10-05-2004.
but when i insert the same using VC++ (MFC) there occurs no problem.
|
|
|
|
|
No "auto conversion" ever takes place. I'd check your code for a compatibility problem with the systems Regional Settings.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How do I reset the DateTimePicker when clicking the reset button in the program
|
|
|
|
|
What do you mean by "reset"?
To set it to the default value, which the current data and time, just use something like this:
myDateTimePicker1.Value = DateTime.Now()
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
That is what I needed I could not figure it out I tried everything thanks a lot.
|
|
|
|
|
1)I made some classes I want to keep them in Namespace
How can i do it in Visual Studio.Net?
2)I want to import this name space in different programs
How Can I do this?
3)I want to make them compiled namespace so that when I want I can use them.
Can I do all this and How
Thanks for any reply
|
|
|
|
|
For each of the apps you want to use your assembly in, all you need to do is add a reference to your assembly (the .DLL you compiled your stuff into), then type the usual Imports myNamespace at the top of the code that will use it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there any way to let the edit mode be able to edit template columns also? Now, I have a template column that have a hyperlink, and I want the edit button to set it to editing mode as well.
Any help appreciated. Thanx in advance
|
|
|
|
|
Hello is there a way to place a control over another control and set its opacity%, basicly what i want to do is to use the picturebox control and place other controls over it
thanks
|
|
|
|
|
Most controls don't support opacity on their own. You'd actually have to make your own versions and owner-draw them. Just for clarification, are you talking about putting the PictureBox control over the top of other controls, or other controls over the top of a PictureBox?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
puting the controls over the picture box, I will look into making them, thanks ur the man
|
|
|
|