|
Oops!!!, it is right, updated. Thanks!!
|
|
|
|
|
WinForms wasn't built with transparancy in mind and it is not very well supported.
Easiest solution is to draw the image yourself, in the Paint-event.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
OK! Could you post some code example to give me an idea in how to proceed? Thank you.
|
|
|
|
|
Delete the control. Change the Paint handler[^] of the container that contained the control to DrawImage[^] the bitmap onto it's canvas.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
How about a different approach using an ErrorProvider[^]?
Public Class Form1
Private err As New ErrorProvider
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
err.Icon = My.Resources.warning ' you can change the icon to display if desired
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If String.IsNullOrEmpty(TextBox1.Text) Then
TextBox1.Focus()
SetError(TextBox1, "please enter something")
Else
'do something
End If
End Sub
Private Sub SetError(ByVal cntrl As Control, ByVal msg As String)
err.SetError(cntrl, msg) ' displays err icon
AddHandler cntrl.Validated, AddressOf ClearErr ' provide a handler to clear the error after leaving the control
End Sub
Private Sub ClearErr(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cntrl As Control = DirectCast(sender, Control)
RemoveHandler cntrl.Validated, AddressOf ClearErr
err.SetError(cntrl, String.Empty) ' setting the message to String.Empty clears the error
End Sub
End Class
|
|
|
|
|
TnTinMn, thank you a lot, that is perfect and for sure I will use it since now on. I'm going to change my code to using this suggestion. For what concern my question, now it is solved.
I discover also that with this suggestion or with just a picturebox, if it is inside a groupbox, the image/icon will not be show complete, it will be cut after the border. Interesting.
(However, it would be interesting to find an answer to what was the original question and make a tutorial to help beginners like me. I saw a lot of people asking the same thing in different forums.)
Thank you again
|
|
|
|
|
First off, you are welcome. Nice to see that a poster actually appreciates our efforts.
Quote: I discover also that with this suggestion or with just a picturebox, if it is inside a groupbox, the image/icon will not be show complete, it will be cut after the border. Sheesh, some people want everything.
Ok, I did a bit of playing around and found that if the target control is parented directly to the Form and not a sub container control, that the ErrorIcon will paint on top of everything. So with a little hacking, here is a custom ErrorProvider that will add a DummyControl directly to the form and post the error against that control instead.
Warning!, I have given this only minimal testing and did not include any fault detection/handling.
Maybe I will clean it up a bit when I have time and post it as Tip/Article.
Give it a go and see how it works for you. Just add this code to your project and use it place of ErrorProvider when you declare an instance.
Public Class FloatingErrorProvider
Inherits ErrorProvider
' Create a storage structure to hold the DummyControls that will
' be parented to the form that contains the control be error reported
' The ErrorProvider will display the ErrorIcon against these controls
' instead of against the source control if the source control is not
' directly parented to the form.
Private AnchorControls As New Dictionary(Of Control, DummyControl)
Private Function GetDummy(ByVal control As Control) As DummyControl
Dim dummy As DummyControl
If AnchorControls.ContainsKey(control) Then
dummy = AnchorControls(control)
Else
dummy = New DummyControl ' a zero sized, non-painting control
dummy.Parent = control.FindForm ' parent to the host form
dummy.SendToBack() ' send to bottom of Z-order
AnchorControls.Add(control, dummy) ' store a reference to it
End If
Return dummy
End Function
''' <summary>
''' sets the dummy control location
''' </summary>
Private Sub SetDummyPosition(ByVal dummy As DummyControl, ByVal control As Control)
Dim errloc As Point
Dim left As Int32 = control.Location.X
Dim right As Int32 = left + control.Width
Dim top As Int32 = control.Location.Y
Dim bottom As Int32 = top + control.Height
Dim mid As Int32 = top + (control.Height \ 2)
Dim align As ErrorIconAlignment = GetIconAlignment(control)
Select Case align
Case ErrorIconAlignment.BottomLeft
errloc = New Point(left, bottom)
Case ErrorIconAlignment.BottomRight
errloc = New Point(right, bottom)
Case ErrorIconAlignment.MiddleLeft
errloc = New Point(left, mid)
Case ErrorIconAlignment.MiddleRight
errloc = New Point(right, mid)
Case ErrorIconAlignment.TopLeft
errloc = New Point(left, top)
Case ErrorIconAlignment.TopRight
errloc = New Point(right, top)
End Select
dummy.Location = control.FindForm.PointToClient(control.Parent.PointToScreen(errloc))
End Sub
Public Shadows Sub SetError(ByVal control As Control, ByVal text As String)
Dim errcontrol As Control
If NeedsDummy(control) Then
errcontrol = GetDummy(control)
SetDummyPosition(DirectCast(errcontrol, DummyControl), control)
Else
errcontrol = control
End If
MyBase.SetError(errcontrol, text)
End Sub
''' <summary>
''' determine if control is parented directly to the form
''' </summary>
Private Function NeedsDummy(ByVal control As Control) As Boolean
Dim frm As Form = control.FindForm
Return frm.Handle <> control.Parent.Handle
End Function
#Region "Method Overrides"
Public Shadows Sub SetIconAlignment(ByVal control As Control, ByVal alignment As ErrorIconAlignment)
If NeedsDummy(control) Then
Dim errcontrol As DummyControl = GetDummy(control)
MyBase.SetIconAlignment(errcontrol, alignment)
SetDummyPosition(errcontrol, control)
Else
MyBase.SetIconAlignment(control, alignment)
End If
End Sub
Public Shadows Function GetError(ByVal Control As Control) As String
Dim errcontrol As Control
If NeedsDummy(Control) Then
errcontrol = GetDummy(Control)
Else
errcontrol = Control
End If
Return MyBase.GetError(errcontrol)
End Function
Public Shadows Function GetIconAlignment(ByVal control As Control) As ErrorIconAlignment
Dim errcontrol As Control
If NeedsDummy(control) Then
errcontrol = GetDummy(control)
Else
errcontrol = control
End If
Return MyBase.GetIconAlignment(errcontrol)
End Function
Public Shadows Function GetIconPadding(ByVal control As Control) As Int32
Dim errcontrol As Control
If NeedsDummy(control) Then
errcontrol = GetDummy(control)
Else
errcontrol = control
End If
Return MyBase.GetIconPadding(errcontrol)
End Function
Public Shadows Sub SetIconPadding(ByVal control As Control, ByVal padding As Int32)
Dim errcontrol As Control
If NeedsDummy(control) Then
errcontrol = GetDummy(control)
Else
errcontrol = control
End If
MyBase.SetIconPadding(errcontrol, padding)
End Sub
#End Region
''' <summary>
''' A non-painting, zero sized control to post an Error against
''' </summary>
Private Class DummyControl
Inherits Control
Public Sub New()
Size = Size.Empty
Visible = True
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'don't paint anything
End Sub
End Class
End Class
|
|
|
|
|
Absolutely, your suggestions help a lot of people like me and we really appreciate too much this kind of effort. Some times, yours helps save us weeks of "try around" the problem.
About the ErrorProvider, great! thank you again. I'll try this new way and give you news about.
Let me know if/when you will be issuing an article, I'll be happy to read it.
|
|
|
|
|
how to zoom a big image with VB?The image size is approximately 6000*8000 pixel.I want it to be completed within 100 milliseconds.Is this possible?
|
|
|
|
|
991176515 wrote: <layer>how to zoom a big image with VB? Same way as smaller images. There's quite some examples on Google on how to draw an image, and here on CodeProject[^].
991176515 wrote: I want it to be completed within 100 milliseconds No. Depending on the machine used, loading the image into memory might even take longer than 100 milliseconds.
Where did the number 100 come from? Is it really a requirement, or do you simply want a "fast zoom"?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It is kind of a requirement.I need to zoom a big image smoothly.It can be achieved only when scaling time in about 70 milliseconds or less. I might ask the question inappropriately.I do not need the whole picture be zoomed,only the part which is visible.But i have had a try with the GDI+,it taked about 1500-3000 milliseconds to zoom the whole picture and 200-300 millseconds to the visible part(it's size is about 1300 * 960).There is another problem. If every time in pan conducting a zooming operation so pan operation will become dull.My current solution is keeping the zoomed image in memory and drawing it to the screen when a pan is requested.But it takes a lot of memory.
If there is a syntax error, please forgive me, because I am using Google Translate.I am chinese and English makes me a headache.
Thank you for your answer.
谢谢!来自中国的感谢。哈哈!
|
|
|
|
|
991176515 wrote: I need to zoom a big image smoothly.It can be achieved only when scaling time in about 70 milliseconds or less. One cannot guarantee execution-time under Windows, due to the way multitasking is implemented. Giving the impression of a smooth transition is a lot easier. In a game, one might abuse the graphics card to blur one image into another.
991176515 wrote: But i have had a try with the GDI+,it taked about 1500-3000 milliseconds to zoom the whole picture and 200-300 millseconds to the visible part(it's size is about 1300 * 960). Imagine you use a second copy of that picture, but scaled to 120 * 96. It'd zoom real fast, but it'd be looking "blocky" due to the resolution. Show that while zooming on the high-res version of your picture on a background-thread. Replace when ready, or abort if the user zooms out or pans.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
A different concept could bring the solution. Do you know Google Earth? They send "tiles", each tile consists of 256*256 pixels. And those tiles are then drawn on the screen, each at its place.
So you could split the big image into several tiles, and do the zoom and draw operations only on the tiles required currently.
|
|
|
|
|
Hi all I keep getting the system null reference exception
I know where it is I just wonder why there is a null.
Public Class Countries
Const ARRAY_UPPERBOUND As Integer = 8
Public Structure WorldCountries
Dim countriesNames As String
Dim countriesAbbreviations As Integer
End Structure
Dim enterCountry(ARRAY_UPPERBOUND) As WorldCountries
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub Countries_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim enterCountry(ARRAY_UPPERBOUND) As WorldCountries
enterCountry(0).countriesNames = "Antarctica"
enterCountry(0).countriesAbbreviations = "AQ"
enterCountry(1).countriesNames = "Bahamas"
enterCountry(1).countriesAbbreviations = "BS"
enterCountry(2).countriesNames = "Canada"
enterCountry(2).countriesAbbreviations = "CA"
enterCountry(3).countriesNames = "Estonia"
enterCountry(3).countriesAbbreviations = "EE"
enterCountry(4).countriesNames = "France"
enterCountry(4).countriesAbbreviations = "FR"
enterCountry(5).countriesNames = "Ireland"
enterCountry(5).countriesAbbreviations = "IE"
enterCountry(6).countriesNames = "Japan"
enterCountry(6).countriesAbbreviations = "JP"
enterCountry(7).countriesNames = "Mexico"
enterCountry(7).countriesAbbreviations = "MX"
enterCountry(8).countriesNames = "Netherlands"
enterCountry(8).countriesAbbreviations = "NL"
End Sub
Private Sub CountryAbbreviationButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CountryAbbreviationButton.Click
Dim cNames As String
Dim bfound As Boolean = False
'get input
cNames = CountryTextBox.Text.ToLower
'Compare input
For l As Integer = 0 To ARRAY_UPPERBOUND
If cNames = enterCountry(l).countriesNames.ToLower Then
bfound = True
AbbreviationTextBox.Text = enterCountry(l).countriesAbbreviations
Exit For
End If
Next
'If Found
If Not bfound Then
MessageBox.Show("Name not Found")
End If
End Sub
End Class
|
|
|
|
|
Member 10409199 wrote: Public Class Countries
Dim enterCountry(ARRAY_UPPERBOUND) As WorldCountries
Private Sub Countries_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim enterCountry(ARRAY_UPPERBOUND) As WorldCountries
...
You have declared a local variable within your Countries_Load method with the same name as the field. You initialize the items in the local variable, and then throw it away. The field is never initialized. When you then try to read from the field in the CountryAbbreviationButton_Click method, the values have not been initialized, and you get a NullReferenceException .
To fix the problem, remove the local variable declaration from your Countries_Load method.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hi I have developed a vbs file which will execute some commands in command prompt and store its output in a text file in same directory where script is run. Now i have converted this vbs file to exe using iexpress wizard by windows. but when i execute the its run in TEMP folder and does not create any text file out . is there any workaround for it to behave same as vbs file when the exe is run.
|
|
|
|
|
On page 21 of IExpress Configuration Wizard[^], it shows a command line switch /t:path that can be used to specify the target folder for extracted files.
|
|
|
|
|
Oh my! Someone read the documentation?! This will never catch on.
|
|
|
|
|
Deserves the up vote just for that. RTFM is an acronym I avoid - they may want me to write the dammed thing first!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks but where i can use this switch
|
|
|
|
|
On the CommandLine when you execute the self-extracting package generated by IEXPRESS.
|
|
|
|
|
I'm getting an error that says:
nullreferenceexception was unhandled by user code
This is my Code:
Protected Sub GrdSorter(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
Dim dt As DataTable = TryCast(ViewState("grdNurseVisits"), DataTable)
Dim dvGridDataView As DataView = dt.DefaultView
Dim strSortOrder As String = ""
If ViewState("SortOrder") Is Nothing Then
ViewState("SortOrder") = "asc"
End If
If ViewState("SortOrder").ToString() = "asc" Then
ViewState("SortOrder") = "desc"
strSortOrder = "desc"
ElseIf ViewState("SortOrder").ToString() = "desc" Then
ViewState("SortOrder") = "asc"
strSortOrder = "asc"
End If
dvGridDataView.Sort = Convert.ToString(e.SortExpression) & " " & strSortOrder
dt = dvGridDataView.ToTable()
grdNurseVisits.DataSource = dt
grdNurseVisits.DataBind()
End Sub
I got the code from this site and there is step I didn't put in because I don't know the correct code.
this is the step:
Populate the ViewState with the datasource of the gridview in the If Not Page.IsPostBack
I don't know how to write that step in vb code
Could some one please let me know how to get this code to work...
|
|
|
|
|
Go to the place where you got the code and ask there.
Veni, vidi, abiit domum
|
|
|
|
|
|
Member 10386526 wrote: Thanks for nothing Think about your issue: you have downloaded some code from somewhere on the internet, without giving us any idea where it came from. There is a part that requires additional code which you expect us to understand, even though we have no idea what the code is based on. You have not explained which line the error occurred on, but you expect us to figure out why it doesn't work.
Veni, vidi, abiit domum
|
|
|
|
|