|
I just happend to encountere the same problem.
May I know how do you convert it using Excel automation?
I am trying to do so but failed. thanks.
|
|
|
|
|
Okay, I just started back working on my web browser, and I want to have my custom context menu show up when the user clicks inside the browser..... This is what I have...
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Browser As New WebBrowser
TabControl1.TabPages.Add("New Tab")
Browser.Name = "Web Browser"
Browser.Dock = DockStyle.Fill
TabControl1.SelectedTab.Controls.Add(Browser)
AddHandler Browser.ProgressChanged, AddressOf Loading
AddHandler Browser.DocumentCompleted, AddressOf Done
Int = Int + 1
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(UrlLocation.Text)
End Sub
That is where I suspect the bit of code will have to go... Since I'm using Tab Control instead of the WebBrowser...
Also, within the Context Menu, I am stuck on two parts...
Private Sub OpenLinkInNewWindowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenLinkInNewWindowToolStripMenuItem.Click
End Sub
Private Sub OpenLinkInNewTabToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenLinkInNewTabToolStripMenuItem.Click
End Sub
What code would I add there to have it allow the user the option to open the Link in a new tab or a new window when they right-click over a link on the current webpage?
This is all I should need to complete my Web Browser for now.... Thanks.
~tbs
|
|
|
|
|
??
The way I create context menus does not involve any ToolStrip thingies. Just:
1. use MouseDown event
2. make sure the right mouse button is clicked
3. create a ContextMenu;
4. populate it (i.e. add menu items with their text, and attach a handler for them);
5. show it.
Something like this does the basics of step 4 (sorry, it's C#):
protected MenuItem addMenuItem(Menu menu, string text, Shortcut sc, EventHandler handler) {
MenuItem menuItem=new MenuItem(text);
menuItem.Click+=handler;
menuItem.Shortcut=sc;
menu.MenuItems.Add(menuItem);
menuItem.Enabled=handler!=null;
return menuItem;
}
PS: there probably is a more modern alternative, using a ContextMenuStrip instead op a ContextMenu;
I haven't used it yet.
|
|
|
|
|
Hi,
It's pretty easy. You need to first make a ContextMenuStrip and add it to the form. It looks like you've already done this because you showed event handlers for items. I'm going to call that ContextMenuStrip "myContextMenuStrip". Clever, huh?
OK, the WebBrowser object has a ContextMenuStrip property. If you can set it at design time, then do that. Otherwise, you can add it to your dynamically-created WebBrowser object:
Dim Browser as New WebBrowser
Browser.ContextMenuStrip = myContextMenuStrip
This assumes you are making a Windows Forms app. I don't think the WebBrowser control for WPF has this property. There are options though.
As for the code to open in a new window or tab, that is a bit more complicated. You would think it would be easy, but it's not really straightforward. Here's why: The WebBrowser control is only a wrapper to a single IE window. Tabs in IE are handled by the application. Each tab contains its own WebBrowser control. (It doesn't actually use the WebBrowser control as such, but this illustrates the point.)
So, the WebBrowser control that you put on your form doesn't know anything about tabbed browsing or other windows. If you want that behavior, you need to create it manually. For example, if you want to open a link in a new tab, you need to:
1) Ascertain the URL
2) Create a new tab
3) Create a new WebBrowser instance and put it on that tab
4) Navigate the new WebBrowser to the URL
It looks like you understand steps 2-4. If you need help finding the URL of the link, let me know.
Opening in a link in a new window involves a similar process:
1) Ascertain the URL
2) Create a new window
3) Create a new WebBrowser instance and put it in that window
4) Navigate the new WebBrowser to the URL
Good luck.
|
|
|
|
|
Well, My main goal right now is to get the custom context menu to work. It didn't show up with the code you supplied. As for the other codes, those can come with time.
|
|
|
|
|
Hmm ... I just did it to verify that it works.
Do this:
- Create a new Windows Forms Application.
- Add a tab control to Form1 with a tab named "TabPage1"
- Add a ContextMenuStrip control to Form1 named "ContextMenuStrip1"
- Add an item to the ContextMenuStrip. (I made an item labeled "Test".)
- Add the following code to the form:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Browser As New WebBrowser
Browser.IsWebBrowserContextMenuEnabled = False
Browser.ContextMenuStrip = ContextMenuStrip1
Me.TabPage1.Controls.Add(Browser)
End Sub
- Run the app, and right click on the browser.
It works perfectly for me.
modified on Monday, August 30, 2010 8:22 PM
|
|
|
|
|
It didn't work. please can someone figure this out?
|
|
|
|
|
This has already been figured out. The solution I gave you works. If you want more assistance, you should provide more information other than, "It didn't work." Then, perhaps I, or someone else, can tell you why it didn't work for you.
The solution I posted it how it is done though. I have done this in two commercial apps, and recoded a simple project (as I described) to verify I didn't miss any steps in describing it to you.
Is it possible you are building a WPF app? As I mentioned earlier, the procedure is different for WPF apps.
|
|
|
|
|
I am building a Windows form, and I am using the Tab Control.
|
|
|
|
|
If you followed the example I gave, my guess is that you did not follow it exactly. The example, as I gave it worked. Howevever, if you subsequently call WebBrowser.Navigate() to go to a web page, then the web browser's built-in context menu kicks in.
My guess is that you didn't try the example as I gave it, or you did, it worked, but then when you tried to incorporate the concept into your application (where Navigate() is called) it stopped working there. That is just my guess though since you haven't really given much information.
In any case, I modified the example by adding the line:
Browser.IsWebBrowserContextMenuEnabled = False
... which will disable the default context menu so that it won't override after you have navigated to a page.
|
|
|
|
|
The only thing is that I am not starting off with a pre setup tab page, it loads the page when the program starts, basically it doesn't have TabPage1 in it, now how can I get the context menu issue to work?
EDIT: Okay, well I thought about it a bit, and I was able to figure it out, using your example and adding a twist which actually happened to work. So I don't need that first TabPage1 anymore, thanks for the help, so now 50% credit to you and 50% credit to me for getting it without TabPage1 lolz.
Now all that I need is that Open link in new tab or window part to work, also that I need to figure out how to program Zoom in and Zoom out, and reset functions, and how to program a Find function, then it will be complete.
modified on Saturday, September 4, 2010 1:44 PM
|
|
|
|
|
It doesn't matter. I was just giving you that simplified example to show you that the approach works. The key is to do the following:
Browser.IsWebBrowserContextMenuEnabled = False
Browser.ContextMenuStrip = ContextMenuStrip1 ' or whatever your ContextMenuStrip is called
Nothing could be simpler. Have you even tried this?
|
|
|
|
|
yes I did, please check my modified post.
|
|
|
|
|
I have been thinking of creating a skinnable application whose skin (the toolbar images) are provided in some sort of "skin file". The problem is, I want all of the images and any other info (like an XML document containing the button fore/back colors to be used) to be grouped into one single file. (Like when you zip many files using WinZip to a single archive file). But I can't open those zip files from VB.
So is there any way to accomplish this task ? (preferably using some kind of open source external library, if one is needed).
(VB 2005, .NET Framework 2.0)
modified on Tuesday, August 24, 2010 7:45 AM
|
|
|
|
|
Pamodh wrote: Like when you zip many files using WinZip to a single archive file
That's what the modern Office-versions do. SharpZipLib[^] would be my choice
I are Troll
|
|
|
|
|
Thanks for the info and the link! I'll try out.
Pamodh.
|
|
|
|
|
You're welcome
|
|
|
|
|
I tried it out and the Zip library works great!!
Thank you so much.
|
|
|
|
|
Hi there,
I have a form containing a listbox showing a list of image names. It's bound
to the database table. When an image name is clicked it shows the image and
imagename in a picturebox and textbox respectively. When no image is selected
in the listbox, a new record can be inserted by browsing a new image in the
picturebox by an openfiledialog, writing the imagename in the textbox and
pressing the OK button. When an image is already selected, the record can be
updated by pressing the same OK button. The data is saved into MSSQL Server
2005. Corresponding table fields are Keycode int autono,
logoname nvarchar(50), logo image.
Now the problem, when I insert a new data with an image everything goes fine
but whenever I try to update an existing data with an image it throws an
exception- 'A generic error occurred in GDI+.' at the following line-
'pic.Image.Save(ms, pic.Image.RawFormat)'. Surprisingly when I update an
existing data without any image in the picturebox no exception is generated.
I have crossed checked it and seems that the problem is just at one point-
'Updating the image from the picturebox'.
I'm almost done all throughout but stuck to this particular point. Please help. Regards.
My code to insert/update the data by OK button and to populate it by listbox
doubleclick follows:
Private ms As MemoryStream
Private arrImage() As Byte
Private conn As SqlConnection
Private cmd As SqlCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Method to bind listbox.
BindListBox(lst, "Select Keycode,LogoName from tbltest", "Logoname", "keycode")
Tag = "Insert"
End Sub
Private Sub lst_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lst.DoubleClick
Dim dr As SqlDataReader
dr = CreateReader("Select LogoName,logo from tblTest where keycode=" & lst.SelectedValue)
If dr.Read Then
txtLogoName.Text = vbNullString & dr("Logoname")
If Not IsDBNull(dr("Logo")) Then
arrImage = CType(dr("Logo"), Byte())
ms = New MemoryStream(arrImage)
pic.Image = Image.FromStream(ms)
ms.Close()
Else
pic.Image = Nothing
pic.Invalidate()
End If
Tag = "Update"
End If
dr.Close()
closeconnection()
arrImage = Nothing
ms = Nothing
End Sub
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
Dim com As SqlCommand
Dim strSql As String
If Tag = "Insert" Then
strSql = "Insert into tbltest (logoname,logo) values ('" & Trim(txtLogoName.Text) & "',@Logo)"
Else
strSql = "Update tbltest set logoname='" & Trim(txtLogoName.Text) & "',Logo=@Logo Where keycode=" & lst.SelectedValue
End If
com = CreateCommand(strSql)
com.Parameters.Add(New SqlParameter("@Logo", SqlDbType.Image))
If Not pic.Image Is Nothing Then
ms = New MemoryStream()
pic.Image.Save(ms, pic.Image.RawFormat)
arrImage = ms.GetBuffer
ms.Close()
com.Parameters("@Logo").Value = arrImage
Else
com.Parameters("@Logo").Value = DBNull.Value
End If
If com.ExecuteNonQuery = 1 Then
closeconnection()
BindListBox(lst, "Select Keycode,LogoName from tbltest", "Logoname", "keycode")
pic.Image = Nothing
pic.Invalidate()
txtLogoName.Clear()
Tag = "Insert"
End If
arrImage = Nothing
ms = Nothing
strSql = Nothing
End Sub
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
With dlg
.Filter = "All Files|*.*|Bitmap|*.bmp|GIF|*.gif|Icon|*.ico|JPEG|*.jpg|PNG|*.png"
.FilterIndex = 5
End With
If dlg.ShowDialog() = DialogResult.OK Then pic.Image = Image.FromFile(dlg.FileName)
End Sub
Public Sub setconnection()
Try
conn = New SqlConnection("Data Source=MyServer;Initial Catalog=TestDB;User Id=sa;Password=;")
conn.Open()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Sub closeconnection()
conn.Close()
End Sub
Public Function CreateCommand(ByVal query As String) As SqlCommand
setconnection()
Dim command As New SqlCommand(query, conn)
Return command
End Function
Public Function CreateReader(ByVal query As String) As SqlDataReader
Dim reader As SqlDataReader
setconnection()
cmd = CreateCommand(query)
reader = cmd.ExecuteReader()
Return reader
End Function
|
|
|
|
|
Hi,
first of all, congrats on a great post. This is how it should be done!
second, it is unfortunate however almost all problems inside GDI/GDI+ cause the same error message to appear and Image.Save() can fail for a whole lot of reasons (access denied, disk full, you name it).
I didn't quite follow all the possible sequences of your logic, however this would be my best guess:
- the file you want to save to is "in use";
- probably because you did open it for creating an Image object, either directly, as in Image.FromFile(); or indirectly as in new Stream(...) and Image.FromStream(). The file would be locked until the image object gets disposed of.
- there isn't really a way to free the file while you still need the image, the Image class needs access to it in case you're going to manipulate the metadata.
- my typical work-around is to never just do Image.FromFile(); instead I do:
Image temp=Image.FromFile(filepath)
Bitmap bm=new Bitmap(temp)
temp.Dispose()
Disposing is what frees the file; using a "copy constructor" for a second image object breaks the connection between the remaining image and the original file.
Hope this helps.
BTW: your code is probably lacking some Dispose() calls anyway; <cod>pic.Image=Nothing is one way of potentially throwing away the last reference to an image without disposing it, causing it to linger around longer than necessary which isn't a good idea as images are rather large objects, and they often lock a file.
|
|
|
|
|
I have found the root of the problem but still couldn't get any solution. When we save the image using this line- 'pic.Image.Save(ms, pic.Image.RawFormat)' the image needs to be in its original format for the RawFormat() method to work properly. So when we click the Browse button, it's browsing an image into the picturebox in its original format. But when we retrieve the image from the database using arrays and streams, though we can view it but it's not in its original format and hence the above mentioned line in btnOk is throwing the exception.
That's exactly the point and that's why inserting a new image is ok, update with a different image is ok but update with the same image is crashing. I think the key to solve it is while retrieving the image from the database if we can somehow convert it to its original format or some format that's recognizable by the RawFormat() method and then show it in the picturebox. In that way when we press btnOk for update, RawFormat() will get the original format of the picture and save it properly.
I don't know how to do it practically or if there's some workaround. Can anybody make a solution out of this? Please assess on this topic and give your views. Regards.
|
|
|
|
|
Why do you insist on using RawFormat at all?
What people most often do when keeping an image in the database, is saving the image to a byte[], then the byte[] to a blob field; AND often also storing the filename so an appropriate file could be re-created.
Maybe you should read a few CodeProject articles on the subject.
|
|
|
|
|
Hello Everybody,
I want to know that how the Barcode Reader Read Barcode Image?
Thanks
If you can think then I Can.
|
|
|
|
|
You scan the the item with a bar-code using a bar-code reader. The reader picks up reflected light and converts it into a code. The code is output as an electrical signal so it can be interpreted by other devices such as a PC.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
hi,
i have a an unbound datagridview, i will load the datagridview programatically by clickng a button.
which is not a problem, the isssue is when i add some data to the new added row, because i have a button
which can able to add a new row. on that new row, i will add new data, when i hit the enter key, the new added
data will go to the top or to the first row which is a bug. it should not be copied to the first row. its
weird because i dont have the function to copy.
thanks is advance
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|