|
Thanks Faris,
ToArgb doesn't exactly fit to my idea but is closest.
In fact I am working arround with :
ListView1.BackColor = Color.FromName("black") '// <-- accept strings
ListView1.Font = New Font("Arial", 8, 2, 0, 0) '// <-- also accept strings or values
or something like that.
The problem I have is that
sw.WriteLine(ListView1.ForeColor)
sw.WriteLine(ListView1.BackColor)
sw.WriteLine(ListView1.Font)
may give a variable number of values if the color is not named but selected custom that give instead three numbers.
|
|
|
|
|
Colors can be saved as a binary Argb representaion which describes the color as an integer value. Color objects can be recreated from the same binary value. You don't need to worry about strings or cases - just save and restore the binary representation of the color.
|
|
|
|
|
Ok then, will look at this further. I have found a solution resticted to the named colors that works properly.
Of course if we are using the custom colors provided by the ColorDialog control, then the use the ARGB parameters is probably the best idea.
And to save the fonts, have you any suggestion ?
Thanks for your help.
Pat
|
|
|
|
|
ARGB works for all colors I would use it in any case. As far as saving fonts, whether you use the Registry, and INI file, text file etc is up to you. The process is always the same - you have to save enough parameter values to recreate the font - Family, Style, Size, Color, etc
|
|
|
|
|
Well, saving all the font parameters looks easy to write in a single sentence:
recreate the font - Family, Style, Size, Color.
It would have been nice to have something like: ListView1.Font.ToString
ListView1.Font.FromString
What we have handy is more confusing :
assuming you have open sw as streamwriter
sw.WriteLine(ListView1.Font) writes :
[Font: Name=Times New Roman, Size=15,75, Units=3, GdiCharSet=0, GdiVerticalFont=False]
sw.WriteLine(ListView2.Font.Size) can give : 9,75 or 12
Question : how can we restore(well simply) a font size defined by : 10 12 9,75 or 15,75 ?
The only way I find is to parse the written string and analyse to look if we have a ',' in the size
and then convert it in 15.75
pfff!
Best Regards
Pat
|
|
|
|
|
So guys, with your help I have got it working pretty nice.
To put it all together and to clean up the table, for those interested:
How to save and restore fonts and colors from controls: (if there is a better way to do it just tell)
' Saving the parameters<br />
Dim sw As New StreamWriter("myInitFile.ini")<br />
' Color of Caracters<br />
sw.WriteLine(RichTextBox1.ForeColor.ToArgb)<br />
sw.WriteLine(ListView1.ForeColor.ToArgb)<br />
' Color of Background<br />
sw.WriteLine(RichTextBox1.BackColor.ToArgb)<br />
sw.WriteLine(ListView1.BackColor.ToArgb)<br />
'Fonts<br />
sw.WriteLine(RichTextBox1.Font.Name)<br />
sw.WriteLine(ListView1.Font.Name)<br />
'Size<br />
sw.WriteLine(RichTextBox1.Font.SizeInPoints)<br />
sw.WriteLine(ListView1.Font.SizeInPoints)<br />
sw.close()<br />
<br />
' retriving the parameters<br />
Dim sr As New StreamReader("myInitFile.ini")<br />
delimStr1 As String = "[] :,.=;"<br />
Dim delimiter As Char() = delimStr1.ToCharArray()<br />
Dim split As String() = Nothing<br />
Dim i, Pos, First As Integer<br />
Dim Words, s As String<br />
Dim token(16) As String<br />
For i = 1 To 6<br />
token(i) = sr.ReadLine<br />
Next i<br />
Pos = 6<br />
For i = 1 To 2<br />
Words = sr.ReadLine<br />
split = Words.Split(delimiter)<br />
Pos += 1<br />
First = 0<br />
For Each s In split<br />
If s <> "" Then<br />
First += 1<br />
If First = 1 Then<br />
token(Pos) = s<br />
End If<br />
End If<br />
Next s<br />
Next i<br />
<br />
RichTextBox1.ForeColor = Color.FromArgb(CInt(Val(token(1))))<br />
ListView1.ForeColor = Color.FromArgb(CInt(Val(token(2))))<br />
RichTextBox1.BackColor = Color.FromArgb(CInt(Val(token(3))))<br />
ListView1.BackColor = Color.FromArgb(CInt(Val(token(4))))<br />
RichTextBox1.Font = New Font(token(5), CShort(Val(token(7))))<br />
ListView1.Font = New Font(token(6), CShort(Val(token(8))))<br />
sr.close()<br />
That's all folks!
This is a simplified extract of my program which work nice. This is my little contribution and thanks your help.
Best regards
Patrice
|
|
|
|
|
One comment. There are APIs that allow reading and writing INI file without having to parse them line by line. For example, you can simply call a function to read or write a certain value from a specific key and section.
I created a module that wraps the apis in simple function calls. If you want a copy, send me your e-mail and I will send it to you.
|
|
|
|
|
What is the fastest way to push data to Excel?
I am iterating through an array and putting the data into excel using the activecell.offset. This takes forever for any reasonable amount of data. I am pushing data from a syncfusion grid; any clever tracks I could do??
|
|
|
|
|
I have a VBA app that exports the activesheet to an xml file. I know that app.config files are just another form of XML files. How can I get this app to export to .config files as well? I am using
ActiveWorkbook.XmlMaps("ConfigParameters_Map").Export to export the data to an XML file. Thanks in advance.
P
|
|
|
|
|
I have upwards of 60 controls on an asp.net page, a little under half being checkboxes, a little under half being labels, and a few textboxes. Going through manually and clearing them if a giant pain, and I know there has to be an efficient way to clear them, like using a For Each loop, checking the type of control, then taking the appropriate action (ie. .Check = false, .Text = "", etc). Problem is I'm pretty new to the .Net framework and I'm not exactly sure how to reference the controls.
Any ideas? Thanks in advance.
-------------------
>abort, retry, fail?
|
|
|
|
|
Hello!...
try this one..........I am considering that you have these all these controls in some parent control like GroupBox.
Here is the code
Dim ctrl As Control
For Each ctrl In GroupBoxName.Controls
ctrl.Text = ""
Next
Now for differentiating b/w the controls say Textbox and Checkbox etc it would be very easy if you have some meaningful control names e.f textbox name starts with 'txt' and checkbox with 'chk' or whatever......If this is so then you can check for the control names for finding out the type of control.......
I hope this will solve ur problem
_mubashir
Marriala Technologies,
Pakistan.
|
|
|
|
|
Thanks for the input! I'm one step closer, but not quite there...
Actually, they're inside in an HTML table inside a Form. I'm pretty close with the logic, I just can't seem to finagle the reference to the form correctly. Here's what I have:
Dim ctrl As Control<br />
For Each ctrl In Page.Form1<br />
If TypeOf ctrl Is CheckBox Then<br />
CType(ctrl, CheckBox).Checked = False<br />
End If<br />
If TypeOf ctrl Is Label Then<br />
CType(ctrl, Label).Text = ""<br />
End If<br />
If TypeOf ctrl Is TextBox Then<br />
CType(ctrl, TextBox).Text = ""<br />
End If<br />
Next
the Page.Form1 is what it's getting caught up on.
Any ideas?
abort, retry, fail?
|
|
|
|
|
got it!
the reference is: Page.Controls.Item(1).Controls
Item(1) being the form.
thanks for your help!
abort, retry, fail?
|
|
|
|
|
Hi a newbee question, is it possible to disable the rigt click of the contextmenu control. i whould like to use a command button to fire the contextmenu instead of the right click, is it. Thank u all Andy38
|
|
|
|
|
Hi everyone, I'm a new member of this wonderfull community.I have got many answers to my problems in you community. I am a beginner in Visual Studio.NET, I lately used Visual Basic 6.0 in programming. But I want to still master Visual BAsic 6.0 but, my problem is I dont want to use Pirated Visual Studio just to program in Visual Basic 6.0. I just want to ask help from your community if you know free IDE for Visual Studio 6.0.I will really appreciate if you help me with this, because I believe that piracy is not accepted in IT.thanks a lot...hope to hear from you guys! thanks.....
yoks
|
|
|
|
|
Wow, before now i didn't realize Visual Studio 6.0 was still that expensive if you tried to buy it. You could look on <shudder &="" cringe=""> eBay . Just try to make sure you are getting a legitamate copy under legal terms (could be more work than it's worth). Otherwise, you could just use a good old text editor with syntax highlighting ( i.e. http://gobby.0x539.de/index.html[^].
Brian Van Beek
Here's my boring blog! [^]
|
|
|
|
|
Hi brian, I'm pretty sure you are a good programmer, thanks for giving me this link.have you tried this text editor in developing VB applications?does it works well?Dont you have any known IDE that is most likely with visual studio 6.0?thanks a lot....hope you can help me..I know you can.
|
|
|
|
|
Anonymous wrote:
developing VB applications?does it works well?Dont you have any known IDE that is most likely with visual studio 6.0?thanks a lot....hope you can help me..I know you can
VB6 != VS6
VB6 (Visual Basic) Apps can only be compiled by the VB6 compiler. Visual Studio (C++) apps can be complied with just about any standard C++ complier.
With .NET it’s a little different; you can use any standard text editor to write your apps. MS offers a free complier for .NET.
So to directly answer your question you need a licensed copy of VB6 to compile the apps. If you’re new to programming and have a copy of Visual Studio 2003 then I suggest learning VB.NET there are some significant changes to the VB language. Learn once not twice.
If you do decide to learn VB.NET then there are a variety of options for you. Get a .NET IDE and search MSDN.Microsoft.com for the free complier.
Good luck and happy programming…
DEBUGGING : Removing the needles from the haystack.
|
|
|
|
|
I am using VBA Excel 2003
I have the following code within a module:
ActiveWorkbook.XmlMaps("config_Map").Export URL:= _
"C:\TextXML.xml"
It works great....ONCE. If the file does not exist, it works exactly like I want it to. However, if the file DOES exist, it throws this run-time error:
Method 'Export' of object 'XmlMap' Failed
How can I get this to overwrite the existing file? Thanks in advance.
P
|
|
|
|
|
PHDENG81 wrote:
ActiveWorkbook.XmlMaps("config_Map").Export URL:= _
"C:\TextXML.xml"
Tell there is a second, optional, parameter that specifies whether to overwrite the file or not. If not specified, it defaults to False, which is no overwrite.
ActiveWorkbook.XmlMaps("config_Map").Export URL:= "C:\TextXML.xml", Overwrite := True
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
You are the man! Thanks for your help and the speedy response.
P
|
|
|
|
|
Is it true that 1 can use the eclipse IDE for developing vb.net applications.I had used eclipse for j2ee programming only till date.how to use it,if it could be used that is.
More dash than cash!!!
|
|
|
|
|
Hi,
Can any bosy tell me ?. What is difference between dispose and finalize in vb.net.
Regards
Rajesh
rajesh
|
|
|
|
|
I am trying to add the asscociated file icon in the listview(
lvwFileNodeList ).
I successfully add the icon for the first found file, but for the rest it
uses the
same icon to display the associated icon. As the following, i am adding the
file icon in the image list with the extension as a key and add this icon
when
adding this file to the list view. there must be the extra step i have to do
does any know what 'm missing?
my envrionment is vb6/xp pro
Me.ImageList2.ListImages.Add , FindExtension(strFileName),
GetIcon(strFilePath, SHGFI_SMALLICON)
Set objListItem = Me.lvwFileNodeList.ListItems.Add
objListItem.SubItems(3) = strFilePath
objListItem.SmallIcon = FindExtension(strFileName)
Public Function GetIcon(filename As String, icon_size As Long) As
IPictureDisp
Dim index As Integer
Dim hIcon As Long
Dim item_num As Long
Dim icon_pic As IPictureDisp
Dim sh_info As SHFILEINFO
SHGetFileInfo filename, 0, sh_info, _
Len(sh_info), SHGFI_ICON + icon_size
hIcon = sh_info.hIcon
Set icon_pic = IconToPicture(hIcon)
Set GetIcon = icon_pic
'GetIcon = sh_info.hIcon
End Function
' Convert an icon handle into an IPictureDisp.
Private Function IconToPicture(hIcon As Long) As IPictureDisp
Dim cls_id As CLSID
Dim hRes As Long
Dim new_icon As TypeIcon
Dim lpUnk As IUnknown
With new_icon
.cbSize = Len(new_icon)
.picType = vbPicTypeIcon
.hIcon = hIcon
End With
With cls_id
.id(8) = &HC0
.id(15) = &H46
End With
hRes = OleCreatePictureIndirect(new_icon, _
cls_id, 1, lpUnk)
If hRes = 0 Then Set IconToPicture = lpUnk
End Function
|
|
|
|
|
i want to execute an executable file from the interface created in VB.net.
i have an exe file named first.exe which needs to be called from a click of a button.
i found the general command for it.. as Shell("C:\first.exe",<parameters>)
this works fine.
what i want to do is try to execute the following command written in dos:
c:\> first < in.txt
and
c:\> first < in.txt > out.txt
thru VB button.
i need help for this.. urgent... :confused
|
|
|
|