|
I creat a button with image menually, like below
Dim aImageButton As New Button
tpgContact.Controls.Add(aImageButton)
aImageButton.Name = entity
aImageButton.Text = ""
aImageButton.Image = Image.FromFile("C:\vb.net\client\images\checkbox_checked.gif")
aimagebutton.ImageAlign = ContentAlignment.MiddleCenter
aimagebutton.FlatStyle = FlatStyle.Flat
aImageButton.Location = New Point(10, y)
aImageButton.Width = 20
aimagebutton.Height = 20
AddHandler aImageButton.Click, AddressOf ImageButtonClickHandler
the problem I have in here is "aImageButton.Image = Image.FromFile("C:\vb.net\client\images\checkbox_checked.gif")" this line of code. If the app install in other computer, then it won't be able to find the same location. What should I do? Is there any way to change the location to fix the need?
Lisa
|
|
|
|
|
There are (2) things you should know about using File Paths:
1) Don't EVER hard code path's like you did in this statement.
2) Don't EVER assume the file is in the "Current Directory" or "Working Directory". Always use fully qualified paths to files.
Right now, you're probably trying to figure out how to use a fully qualified path without knowing what that path is???
Easy. What you should be doing is building a path using a "known" location as a reference. The Application.StartupPath property will tell you from which folder your .EXE was loaded, or launched, from. If your .GIF file is in the same folder as your .EXE, you have a "known" starting point. All you have to do now is build the complete path to the file.
But wait a minute! Most beginners will use string concatenation to do this. Something like:
Dim myGifFile As String = Application.StartupPath & "\myGifFile.GIF"
Don't EVER do this! Instead, use a class that's specifically designed to do this, and more, using the proper path seperation characters and build rules for the platform that it's running on. The Path class does just this. Specifically, what you're looking for is:
Dim myGifFile As String = Path.Combine( Application.StartupPath, "myGifFile.GIF" )
Path.Combine takes (2) arguments. The first being the beginning of the path and the second being the ending. You don't have to worry about prepended or appended path seperation characters either. Path.Combine will take care to make sure that the path it generates is in a legal format.
Assuming that your .GIF image is in the same folder as the .EXE, your code should look more like this:
' Build a new button control
Dim aImageButton As New Button
With aImageButton
Dim imagePath As String = Path.Combine( Application.StartupPath, "checkbox_checked.gif" )
.Image = Image.FromFile( imagePath )
.Name = entity
.Text = ""
.ImageAlign = ContentAlignment.MiddleCenter
.FlatStyle = FlatStyle.Flat
.Location = New Point(10, y)
.Width = 20
.Height = 20
End With
' Attach the Click Event handler
AddHandler aImageButton.Click, AddressOf ImageButtonclickHandler
' Finally, add the control to the form
tpgContact.Controls.Add(aImageButton)
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks..that's so helpful...
I have another issue in my vb app. here is my coding:
private function contactView()
'connect to data and do the query.....
'user the DataReader to read the value from the query...
'Query: SELECT primary_contact, entity_id from Conatcts
Do While DR.Read()
primaryContact = DR.GetBoolean(0)
entity = DR.GetInt32(1)
'creat a image button
If primaryContact = True Then
Dim aImageButton As New Button
With aImageButton
Dim imagePath As String = Path.Combine(Application.StartupPath, "checkbox_checked.gif")
.Image = Image.FromFile(imagePath)
.Name = entity
.Text = ""
.ImageAlign = ContentAlignment.MiddleCenter
.FlatStyle = FlatStyle.Flat
.Location = New Point(10, y)
.Width = 20
.Height = 20
End With
' Attach the Click Event handler
AddHandler aImageButton.Click, AddressOf ImageButtonclickHandler
' Finally, add the control to the Form
tpgContact.Controls.Add(aImageButton)
Else
Dim aImageButton As New Button
With aImageButton
Dim imagePath As String = Path.Combine(Application.StartupPath, "checkbox_blank.gif")
.Image = Image.FromFile(imagePath)
.Name = entity
.Text = ""
.ImageAlign = ContentAlignment.MiddleCenter
.FlatStyle = FlatStyle.Flat
.Location = New Point(10, y)
.Width = 20
.Height = 20
End With
' Attach the Click Event handler
AddHandler aImageButton.Click, AddressOf ImageButtonclickHandler
' Finally, add the control to the Form
tpgContact.Controls.Add(aImageButton)
End If
y += 25
Loop
end function
Public Sub ImageButton1ClickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
results = CType(CType(sender, Button).Name, Int32)
Dim DA As New OleDbDataAdapter
objConn.Open()
DA.SelectCommand = New OleDbCommand
DA.SelectCommand.Connection = objConn
DA.SelectCommand.CommandType = CommandType.Text
DA.SelectCommand.CommandText = "UPDATE Contacts set primary_contact = 0 WHERE client_entity_id = " & client_entityID
DA.SelectCommand.ExecuteNonQuery()
Dim DA2 As New OleDbDataAdapter
DA2.SelectCommand = New OleDbCommand
DA2.SelectCommand.Connection = objConn
DA2.SelectCommand.CommandType = CommandType.Text
DA2.SelectCommand.CommandText = "UPDATE Contacts set primary_contact = 1 WHERE entity_id = " & results
DA2.SelectCommand.ExecuteNonQuery()
objConn.Close()
End Sub
---here is my problems, after the click, I want to rebind the data, so the form will show up the change, I can't recall the function in the ImageButton1ClickHandler, what should I do?
Lisa
|
|
|
|
|
Lisana wrote:
I can't recall the function in the ImageButton1ClickHandler, what should I do?
If you want to call the code in the handler, just move the code to another method outside the handler.
Public Sub ImageButton1ClickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
Dim results As Int32 = CType(CType(sender, Button).Name, Int32)
BindDataSources(results)
End Sub
Public Sub BindDataSources(ByVal entityID As Int32)
' I'm assuming client_entityID is a "global" variable
objConn.Open()
Dim DA As New OleDbDataAdapter
DA.SelectCommand = New OleDbCommand
With DA.SelectCommand
.Connection = objConn
.CommandType = CommandType.Text
.CommandText = "UPDATE Contacts set primary_contact = 0 WHERE client_entity_id = " & client_entityID
.ExecuteNonQuery()
End With
Dim DA2 As New OleDbDataAdapter
DA2.SelectCommand = New OleDbCommand
With DA2.SelectCommand
.Connection = objConn
.CommandType = CommandType.Text
.CommandText = "UPDATE Contacts set primary_contact = 1 WHERE entity_id = " & entityID
.ExecuteNonQuery()
End With
objConn.Close()
End Sub
Now you can call BindDataSources from anywhere in your code, so long as you provide it an entityID.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I think you misunderstood my meaning, I want to call the function contactView not the update query.
Public Sub ImageButtonClickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
results = CType(CType(sender, Button).Name, Int32)
contactView() 'give me error
end sub
it gave me error when I call the contactView() in the ImageButtonClickHandler
The main thing I want to do in here is when the blankImageButton Click, then go the database to change the pimary_contact to 1, the other pimary_contact=1 to 0, at the same time, the button image changes as well, in the output, the imagebutton didn't change when I click, but the database is updated. I have to close the window, then reopen again, then it shows the change.
Lisa
|
|
|
|
|
Whopps! My mistake.
What's the error?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The main thing I want to do in here is when the blankImageButton Click, then go the database to change the pimary_contact to 1, the other pimary_contact=1 to 0, at the same time, the button image changes as well, in the output, the imagebutton didn't change when I click, but the database is updated. I have to close the window, then reopen again, then it shows the change.
Lisa
|
|
|
|
|
You've got a major design flaw in there. Every time you call contactView, you're created new buttons. But, you're never removing the old ones that you created.
What are you trying to do with the buttons? Implement paging?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How can I remove the old buttons when before contactView() called?
those buttons are checked and unchecked buttons, if you have 5 contacts, there is only one pimary contact that would be the checked buttons, if you want to change your pimary contact, then click one unchecked button, the one you just clicked will become the pimary contact(changed to checked button), the old pimary contact changed to unchecked button.
like this:
-Unchecked X checked
5 lists, when the second record click, then
old new
- -
- X
- -
X -
- -
Lisa
|
|
|
|
|
If there is some compelling reason whay you absolutely have to add the buttons at run-time - like the numebr of buttons changes depending on the number of contacts, then load them all one time when the form is initialized. After you create each button, also add it to a local collection.
Then when a person clicks on a button, enumerate the local collection, set each button's state to unchecked, then continue to process the click event to perform the query and reset the newly checked contact.
This will be much faster than trying to constantly add and remove buttons and their event handlers from the form. You also do not need to keep track of the current state of any given button, because you simply reset them all to unchecked whenever one is clicked.
Unless you have a lot of buttons, simply enumerating the list will be about as fast, and much simpler than writing code to keep track of the the button state.
Robert
|
|
|
|
|
it's very complicate in this data binding..I have a very hard time to get around all of those.
this is my form look like:
PC|View|Name|Phone|email
PC column: imagebutton
View: button --when the user click button, then open a form to view the detail, and the user and change the data, when the form closed, in this form's data has to be updated as well, this is a hard part I haven't found a way to fix the problem..in my app now, I can't get to refresh and load the update data, I have to close this form and open again to get the newest data.
Name: textbox
phone: combobox, binding all the phone number in db to combobox
email: button - when the user click the button, then auto start a outlook to send email.
I can't use datagrid because I can't find a way to add those controls to datagrid. so I only can use the dataReader to menually creat those needed in my app. that is very annoying to do that. but I can't find any other way to do it. IF you know a better way to do it, please tell me. I will very appricate it.
Lisa
|
|
|
|
|
Wow! Talk about doing it the hard way!
The DataGrid is the tool choice for this project, but admittedly, it's not an easy tool to learn to use. Ummmm... Try seeing what you can glean from this[^] little article by Omri. There's even a link in it to show you how to get a ComboBox column into a DataGrid.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks;)
how about a button inside datagrid, and when it click, open another window? This is I always want to do it, but I just can't get around it, it includes some drawing and you need to creat a button by your own...do you have any experience for the button inside datagrid. I know the combobox inside datagrid is much easier to do it than button. I have buttons and combobox at the same time.
Lisa
|
|
|
|
|
expression is not a method.
Lisa
|
|
|
|
|
TextBox, Button, CheckBox and most (not all but most) NET controls can display images from an ImageList.
You will find that your code is simpler, easier to deploy, and easier to manage in general if you just abandon the whole approach of loading images from a file. Put them in an ImageList control instead.
Robert
|
|
|
|
|
Hi there
I want to use a wavelet filter in my program but i can't find any documentation and i dont know if VB is able to do it. I tried to use CxImage (which seems to work with matrice ?!) but I'm a little bit lost....
Thx for answerds
Anthony
|
|
|
|
|
There's no reason why you shouldn't be able to use VB to do this. If you don't know anything about the algorithm, just Google for it. Results for "wavelet filter algorithm vb"[^].
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
<br />
<br />
<% @Import Namespace="System.Data" %><br />
<script language="vb" runat="server"><br />
Dim searchword as String<br />
Dim pls as New DataTable()<br />
<br />
Sub Page_Load(sender as Object, e as EventArgs)<br />
BuildDataStore()<br />
<br />
completeData.DataSource = pls<br />
completeData.DataBind()<br />
End Sub<br />
<br />
<br />
Sub BuildDataStore()<br />
Dim dr as DataRow<br />
<br />
pls.Columns.Add(new DataColumn("Results", GetType(String)))<br />
<br />
dr = pls.NewRow()<br />
dr(0) = "If only God would give me some clear sign! Like making a large deposit in my name at a Swiss bank."<br />
pls.Rows.Add(dr)<br />
<br />
dr = pls.NewRow()<br />
dr(0) = "Is sex dirty? Only when it's being done right."<br />
<br />
pls.Rows.Add(dr)<br />
<br />
dr = pls.NewRow()<br />
dr(0) = "On the plus side, death is one of the few things that can be done just as easily as lying down."<br />
pls.Rows.Add(dr)<br />
<br />
dr = pls.NewRow()<br />
dr(0) = "I took a speed reading course and read 'War and Peace' in twenty minutes. It involves Russia."<br />
pls.Rows.Add(dr)<br />
<br />
dr = pls.NewRow()<br />
dr(0) = "To *you* I'm an atheist; to God, I'm the Loyal Opposition."<br />
pls.Rows.Add(dr)<br />
<br />
dr = pls.NewRow()<br />
dr(0) = "Sex without love is an empty experience, but as empty experiences go, it's a pretty good empty experience."<br />
pls.Rows.Add(dr)<br />
<br />
dr = pls.NewRow()<br />
dr(0) = "It's not that I'm afraid to die. I just don't want to be there when it happens."<br />
pls.Rows.Add(dr)<br />
<br />
dr = pls.NewRow()<br />
dr(0) = "What if everything is an illusion and nothing exists? In that case, I definitely overpaid for my carpet."<br />
pls.Rows.Add(dr)<br />
<br />
dr = pls.NewRow()<br />
dr(0) = "Interestingly, according to modern astronomers, space is finite. This is a very comforting thought-- particularly for people who can never remember where they have left things."<br />
pls.Rows.Add(dr)<br />
<br />
dr = pls.NewRow()<br />
dr(0) = "Eighty percent of success is showing up."<br />
pls.Rows.Add(dr)<br />
End Sub<br />
<br />
<br />
Sub BindData(strQuery as String)<br />
searchword = strQuery<br />
<br />
Dim dv as DataView<br />
dv = New DataView(pls)<br />
dv.RowFilter = "Results LIKE '%" & Regex.Replace(searchword,"'","''") & "%'"<br />
<br />
SearchResults.DataSource = dv<br />
SearchResults.DataBind()<br />
End Sub<br />
<br />
<br />
Function Highlight(Search_Str as String, _<br />
InputTxt as String, _<br />
StartTag as String, _<br />
EndTag as String) As String<br />
<br />
Dim ResultStr As String <br />
Return Regex.Replace(InputTxt, "\b(" & Regex.Escape(Search_Str) & ")\b", _<br />
StartTag & "$1" & EndTag, RegExOptions.IgnoreCase)<br />
End Function<br />
<br />
<br />
Sub searchQuotes(sender as Object, e as EventArgs)<br />
BindData(SearchTerm.Text)<br />
SearchResults.Visible = True<br />
End Sub<br />
</script><br />
<br />
<style type="text/css"><br />
.highlight {text-decoration: none;color:black;background:yellow;}<br />
</style><br />
<br />
<form runat="server"><br />
Text to Search: <asp:TextBox id="SearchTerm" runat="server" /><br />
<asp:button runat="server" Text="Search Woody Allen Quotes"<br />
OnClick="searchQuotes" /><br />
<p><br />
<asp:DataGrid runat="server" id="SearchResults" AutoGenerateColumns="False"<br />
Visible="False" ShowHeader="False"><br />
<Columns><br />
<asp:TemplateColumn><br />
<ItemTemplate><br />
<%# Highlight(searchword, DataBinder.Eval(Container.DataItem, "results"), "", "") %><br />
</ItemTemplate><br />
</asp:TemplateColumn><br />
</Columns><br />
</asp:DataGrid><br />
<p><br />
The Data Being Search<br />
<asp:datagrid runat="server" id="completeData" ShowHeader="False" /><br />
I imported this code in Visual studio.net and change on click events and other thing that they have to change but
there is a problem ! Framework said that error BC30390: 'webapplication1.webform1.searchwords' is not
accessible in this context because it is 'Private'.
any idea ?
onezero@gmail.com
|
|
|
|
|
First off, this questio njbelongs in the ASP.NET Forum, not VB.
Yeah, you can't use the variable searchword outside the <script> block. When you called Highlight , you tried to use a variable that was not visible outside the script block.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
how can i connect the microsoft chart control with a table in the db so i can plot the data on the MS chart control.
|
|
|
|
|
Hello
I want to preview MS office documents (word and excel) on windows form using VB.NET (example how to do this can be in any language, but VB id preffered ). Somewhere I have found, that this is done using Microsoft Web Browser component (SHDocVw.dll). Well, this seems to almost work, but...
Problem #1:
When I try to open an office document caling webBrowser.navigate("file:///some_document.doc") , it pop-ups a dialog offering me to open or download this document. There is a check box, so next time I try to open this kind of documents, it will not ask me, but display it.
Problem #2:
Vhen a document is opened in a web browser, it is editable. Well, this is normal, because there is an instance of MS word opened in the web browser.
What I need:
I need to show (preview) an office document in a windows form. The "preview" meens, it must be read only and not bothering users with some dialog if they want to download or open it.
Thanks a lot for any help.
Satano.
|
|
|
|
|
i have this code and i want this as a windows service.
i like this to execute every 20 secs
Dim olapp As New Outlook.Application
Dim olNs As Outlook.NameSpace
Dim myrecipient, myfolder
Dim myitems As Outlook.Items
Dim mymail As Outlook.MailItem
Dim myitem As Object
Dim myConnection As SqlConnection
Dim myCommand As SqlDataAdapter
Dim cmd As New SqlCommand
olapp = CreateObject("Outlook.application")
olNs = olapp.GetNamespace("MAPI")
myrecipient = olNs.CreateRecipient("someusername")
myrecipient.resolve()
If myrecipient.resolved Then
myfolder = olNs.GetSharedDefaultFolder(myrecipient, Outlook.OlDefaultFolders.olFolderInbox).Items
End If
myitems = myfolder
myConnection = New SqlConnection("Data Source=.....")
myCommand = New SqlDataAdapter
myitems = myitems.Restrict("[Unread] = true")
myConnection.Open()
For Each myitem In myitems
On Error Resume Next
cmd = New SqlCommand("Insert into NewMessages (EntryID,SenderName,Subject,ReceivedTime,Body,UnRead) values(@EntryID ,@SenderName,@Subject,@ReceivedTime,@Body,@UnRead)", myConnection)
cmd.Parameters.Add(New SqlParameter("@EntryID", SqlDbType.Variant))
cmd.Parameters("@EntryID").Value = myitem.entryid
cmd.Parameters.Add(New SqlParameter("@SenderName", SqlDbType.NVarChar, 100))
cmd.Parameters("@SenderName").Value = myitem.sendername
cmd.Parameters.Add(New SqlParameter("@Subject", SqlDbType.NVarChar, 1000))
cmd.Parameters("@Subject").Value = myitem.subject
cmd.Parameters.Add(New SqlParameter("@ReceivedTime", SqlDbType.DateTime))
cmd.Parameters("@ReceivedTime").Value = myitem.ReceivedTime
cmd.Parameters.Add(New SqlParameter("@Body", SqlDbType.Variant))cmd.Parameters("@Body").Value = myitem.Body
cmd.Parameters.Add(New SqlParameter("@UnRead", SqlDbType.NChar, 5))cmd.Parameters("@UnRead").Value = myitem.UnRead
cmd.ExecuteNonQuery()
Next myitem
myConnection.Close()
olapp = Nothing
olNs = Nothing
myrecipient = Nothing
myfolder = Nothing
myitem = Nothing
myitems = Nothing
myrecipient = Nothing
i've already created a service for this one but, on its first start, it extracts unread mails, but when new mails come, it does not extract anything and when i checked on the application log it says, Microsoft Office 11 - Rejected safe mode action - Microsoft Outlook. on the system log: DCOM - The server {0006F03A-0000-0000-C000-000000000046} did not register with DCOM within the required timeout. I already uninstalled and killed the service but i'm still getting this errors on the eventlog. why is this so? i think i messed everything up. :'( please help me resolve this..
|
|
|
|
|
hi
is it necessary to have smtp server on that machine to send mail.
suppose i dont have the smtp server than how can i send mail through code(dont tell me the code just what process should be followed).
|
|
|
|
|
Private Sub showMonth()
MonthlyCalendar1.FirstDate = d
txtMonth.Text = DatePart(DateInterval.Month, d) & "," & " " & DatePart
(DateInterval.Year, d)
End Sub
The above code displays the month in a number format like 4, 2005. I want to know how to modify the above code to display the month in April, 2005 format. How should I do it? I have tried select case but I get an error saying that I can't combine 'Date' with an 'Integer'.
|
|
|
|
|
Try the command Format
Here dt is a datetimepicker control
Format(Me.dt.Value, "d/MMM/yyyy")
|
|
|
|
|