|
i able to pass around the image val from form 2 to form 1 ,
but wats wrong when i want to pass it again from form1 to form3???
i try to add again with those coding but i cant run the program ,it keep on running until my computer hang.. so have to stop the program manually. I guess the program having the unfinished loop after i add the coding. I not sure able to put the form2 and form1 image handling together or not, but thats where the infinite loop comes out. such as
Form1:
Public Event NewImage(ByVal i As Image)
If Label2.Text = 1 Then
RaiseEvent NewImage(picturebox(x).Image).....
Private Sub opentokengalery()
AddHandler token.NewImage, AddressOf newimagehandler
End Sub
Public Sub newimagehandler(ByVal i As Image)
PictureBox1.Image = i
End Sub
-- modified at 7:36 Friday 24th February, 2006
|
|
|
|
|
hellow to all ..
is there a way to update a datagird , with out loading all the query agine ?
because when i load the query agine i lose the sorting that i had made on the datagrid ..
anyhelp appreciated ...
thxx
|
|
|
|
|
The form is 510 by 360. One half of it has to go from black to green. The other Half from blue to black. I think you're supposed to create a loop of some sort to change each line using the pen. But How?? Remember I am only a beginner so, i know only the basics of VB.net.
E-mail me at tate_thomasster@gmail.com and i can give you the source code to see if you can point out my mistakes.
If you are familar with the Thomson Course Technology book, Visual Basic.Net:
An object-oriented approach, then it is Chapter 6, Exercise 2. This is my first time working with Vb.Net.
Ty
|
|
|
|
|
Okay. From the e-mail you sent me, you want to split your form into 2 triangles. In the top left corner, you want a triangle with a color gradient from black to green. In the bottom right corner, you want a triangle with a color gradient blue to black.
What you need is a GradientBrush to draw this for you. You'll also need to catch your form's Paint event so that you can draw these triangle onto your form. The drawing is done on the Paint method's passed in Graphics object.
The code should look something like this.
Private Sub MyForm_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles MyBase.Paint
Dim brGradient As System.Drawing.Drawing2D.LinearGradientBrush
Dim points() As PointF
'
' Validate.
If (e Is Nothing) Then Return
If (e.Graphics Is Nothing) Then Return
'
' Get form's client size.
Dim clientRectangle As New System.Drawing.Rectangle(0, 0, _
Me.ClientSize.Width, Me.ClientSize.Height)
'
' Draw the green gradient triangle.
brGradient = New System.Drawing.Drawing2D.LinearGradientBrush(clientRectangle, _
Color.Black, Color.LightGreen, _
System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
points = New PointF() {New PointF(0, 0), _
New PointF(clientRectangle.Width, 0), _
New PointF(0, clientRectangle.Height)}
e.Graphics.FillPolygon(brGradient, points)
brGradient.Dispose()
'
' Draw the blue gradient triangle.
brGradient = New System.Drawing.Drawing2D.LinearGradientBrush(clientRectangle, _
Color.Blue, Color.Black, _
System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
points = New PointF() {New PointF(0, clientRectangle.Height), _
New PointF(clientRectangle.Width, 0), _
New PointF(clientRectangle.Width, clientRectangle.Height)}
e.Graphics.FillPolygon(brGradient, points)
brGradient.Dispose()
End Sub
|
|
|
|
|
Okay so I sort of understand. But the way I was trying to do it was create a line that draws the color in a loop repeatedly until it changes to the other color. Like creating three different varaibles and incremeting the green variable from 0 to 255. Is that a good way of doing it?? Here's some of the code(I haven't quite yet created the loop)...
Private Sub frmSplash_Paint(ByVal sender As Object, ByVal e As _ System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim graCurrent As Graphics = e.Graphics
Dim recCurrent As Rectangle, colCurrent As Color
Dim sbCurrent As SolidBrush, penCurrent As Pen
Dim intHeight As Integer, intWidth As Integer
recCurrent = New Rectangle(0, 0, Me.Width, Me.Height)
sbCurrent = New SolidBrush(Color.Green)
graCurrent.FillRectangle(sbCurrent, recCurrent)
Dim CounterLoop As Integer = 1
intHeight = 0
For intwidth = 0 To Me.Width Step _
ToInt32(Me.Width / 255)
penCurrent = New Pen(Color.FromArgb(0, 0, 0, 0))
Select Case CounterLoop
Case 1
colCurrent = Color.FromArgb(0, 0, 0, 0)
CounterLoop += 1
Case 2
colCurrent = Color.FromArgb(0, 0, 1, 0)
CounterLoop += 1
Case 3
colCurrent = Color.FromArgb(0, 0, 2, 0)
CounterLoop += 1
Case 4
colCurrent = Color.FromArgb(0, 0, 3, 0)
CounterLoop += 1
Case 5
colCurrent = Color.FromArgb(0, 0, 4, 0)
CounterLoop += 1
Case 6
colCurrent = Color.FromArgb(0, 0, 5, 0)
CounterLoop += 1
Case 7
colCurrent = Color.FromArgb(0, 0, 6, 0)
CounterLoop += 1
Case 8
colCurrent = Color.FromArgb(0, 0, 7, 0)
CounterLoop += 1
Case 9
colCurrent = Color.FromArgb(0, 0, 8, 0)
CounterLoop += 1
Case 10
colCurrent = Color.FromArgb(0, 0, 10, 0)
CounterLoop += 1
End Select
graCurrent.DrawLine(penCurrent, 0, ToInt32(Me.Height / 180), _
ToInt32(Me.Width / 255), 0)
Next
End Sub
End Class
Ty
-- modified at 10:04 Friday 24th February, 2006
|
|
|
|
|
You can draw the gradient yourself with individual lines. It just takes more effort (and might not be as efficient). GDI+ can do the work for you with a single Gradient brush, like in the code I gave you.
Your code isn't going to work though. For one thing, you're assigning a new Color to "colCurrent" on every pass in the loop, but you never assigned the color to your pen. You should be creating the pen with this color at the bottom of your switch statement.
penCurrent = New Pen(colCurrent)
Also, you really shouldn't be using a switch statement. There are a lot of colors for you to go through, which would involve too many case statements. Instead, you should create red, green, and blue integer variables and increment the ones you need on every pass. Luckily you're transitioning from black to another color, which involves just incrementing up from (0,0,0). If your starting color was not black, then creating a gradient would be much, much harder.
Also, you need to call your brush's and pen's Dispose() method when you're done using them. Otherwise you'll have GDI leaks. As a general rule, any object that you've created should be disposed if it has a Dispose() method. That means disposing the pen before overwriting it with a new one on every pass in the loop.
|
|
|
|
|
Here's a follow up to drawing a gradient with individual lines...
First you need to figure out how to calculate the gradient. The next pen color that you calculate within your loop is determined based on your x position in the form. For the first triangle, we should convert those x coordinates into green color percentages, where the left most x on the form is 0% (black) and the right most x on the form is 100% (green).
Dim percentGreen As Double = x / Me.ClientSize.Width
Next, we convert that into a color value which ranges between 0 and 255.
Dim greenValue As Integer = percentGreen * 255
Simple math so far. Now since we're drawing a triangle, we're going to need to use trigonometry to calculate the y. We're going to iterate the x from left to right, and draw a line top to bottom, but that bottom is going to get shorter and shorter on every pass of the loop. The width of the triangle from x to the right most point will be...
Dim width As Double = Me.ClientSize.Width - x
We need to calculate the angle of the right most point on the triangle. This is a constant value. You only need to calculate this once.
' Tangent(Angle) = Opposite / Adjacent<br />
' Angle = ArcTangent(Opposite / Adjacent)<br />
' This angle is in radians!<br />
Dim angle As Double = Math.Atan(Me.ClientSize.Height / x)
Now that you have the width and angle, you can calculate the height.
' Opposite is the y, which the part we want.<br />
' Tangent(Angle) = Opposite / Adjacent<br />
' Opposite = Tangent(Angle) / Adjacent<br />
Dim y As Double = Math.Tan(angle) / x
So, all in all, it should look something like this. I'll leave the rest to you.
' This is the loop for the green triangle.
For x As Integer = 0 To (Me.ClientSize.Width - 1) Step 1
' Calculate green value here.
' Create pen here using calculated color value.
' Calculate x and y here.
' Draw line here via e.Graphics.DrawLine().
' Dispose pen here.
Next
|
|
|
|
|
Thank You for helping me. And a last request if you don't mind. Here is the final code to the splash screen. Just look over it and see if i got the general idea right.
Private Sub frmSplash_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim graCurrent As Graphics = e.Graphics
Dim colCurrent As Color, colCurrent1 As Color
Dim penCurrent As Pen, penCurrent1 As Pen
Dim LineLoop As Integer, LineLoop1 As Integer
'Sets the first coordiante for the green triangle.
Dim Greenx1 As Integer = 0
Dim Greenx2 As Integer = 0
Dim Greeny1 As Integer = 0
Dim Greeny2 As Integer = Me.Height
'Sets the first coordiante for the blue triangle.
Dim Bluex1 As Integer = Me.Width
Dim Bluex2 As Integer = 0
Dim Bluey1 As Integer = Me.Height
Dim Bluey2 As Integer = 0
' Sets the "step value" or how far up and over for each line created.
Dim StepX As Integer = ToInt32(Me.Width / 255)
Dim StepY As Integer = ToInt32(Me.Height / 255)
' Darwing of the Green Triangle
For LineLoop = 0 To 255
colCurrent = Color.FromArgb(0, LineLoop, 0)
penCurrent = New Pen(colCurrent, 4)
graCurrent.DrawLine(penCurrent, Greenx1, Greeny1, Greenx2, Greeny2)
Greenx1 = Greenx1 + ToInt32(StepX)
Greeny1 = Greeny1 + ToInt32(StepY)
Greenx1 += 1
Greeny1 += 1
Greeny2 += 1
Next LineLoop
' Drawing of the Blue Triangle
For LineLoop1 = 255 To 0 Step -1
colCurrent1 = Color.FromArgb(0, 0, LineLoop1)
penCurrent1 = New Pen(colCurrent1, 4)
graCurrent.DrawLine(penCurrent1, Bluex1, Bluey1, Bluex2, Bluey2)
Bluex1 = Bluex1 + ToInt32(StepX)
Bluey1 = Bluey1 + ToInt32(StepY)
Bluey1 -= 1
Bluey2 -= 1
Bluex2 += 1
Next LineLoop1
End Sub
Ty
|
|
|
|
|
It's pretty close. It doesn't quite draw corner to corner on my form. And there is a slight white gap between the 2 triangles. My form is a different size than yours. But it is really close. Good job so far.
Two things...
1) I had a compile error on your ToInt32() calls. I had to change them to Convert.ToInt32().
2) You need to Dispose your pens at every pass of your loop. Both loops really. Do it like this...
penCurrent.Dispose
Next LineLoop
|
|
|
|
|
I am going to show a form, which only have a label to show "Now Loading".
Then go to a last of dos command in shell().
By Dave, I know that add a "Application.DoEvents()" to meet the goal.
Further question, In this case, we cannot using messageForm.showdialog(me) to make the user cannot control the main form.
any idea for these case? Thank you.
|
|
|
|
|
Hi All
I'm building a VS 2005 app which needs to use automation to create Excel and Word processes and create Macro modules within them to handle the return to the VS app. Hit a major bug, and then tried KB 303872 (How To Create an Excel Macro by Using Automation from Visual C# .NET) and KB 303871 (How To Create an Excel Macro by Using Automation from Visual Basic .NET). Both fail on the line below...
oModule.CodeModule.AddFromString(sCode)
Error says Error Loading Type Library/DLL - no real other info
Have tried on other PCs - checked the 2003 PIA assemblies are okay (all seem fine - have reinstalled in any case to be sure). Not related to the permissions problem that can happen which I've already resolved. Anyone any ideas pls? Or any kind soul able to quickly copy and paste the code from one of the KB articles and let me know if they get same error? Any help much appreciated - lost most of yesterday on this and you may bring someone back from the brink of insanity!
Cheers
Dave
It's not the pace of life that worries me, it's the sudden stop at the end...
|
|
|
|
|
Hi,
Is it possible for a menu to appear only when a user right clicks the listbox item?
How can we enable right-click menus?
|
|
|
|
|
create a context menu and assign it to listbox.contextmenu
|
|
|
|
|
Hi
I'm trying to use a dataview rowfilter to get the Max, Min, and Ave Order Values for a particular PartNo. (I cannot change the base SQL query, since depending on user input, I need to loop though anything from 10 to 1000 rows, and for each row, get the min, max and average - Too many queries over a network??). For this reason, I pull the whole table via SQL, and am trying to use rowfilters to get the desired values for each row
Dataview.RowFilter = "PartNo = '123' AND Ave(Cost)" gives an error similar to this: Cannot perform AND operation on Boolean and Double. I assume the Boolean part is 'PartNo = '123' and the Double would be the Average Cost returned which does make sense.
Any ideas how I could do this??
Basically I want to implement the following SQL using a rowfilter:
SELECT Ave(Cost) FROM PurchaseOrders WHERE PartNo = '123'
Thanks in advance!!
-- modified at 6:01 Thursday 23rd February, 2006
|
|
|
|
|
Hi,
Dim dtItemCost As New DataTable("Cost")<br />
<br />
dtItemCost.Columns.Add(New DataColumn("PartNo", GetType(String)))<br />
dtItemCost.Columns.Add(New DataColumn("Cost", GetType(Double)))<br />
<br />
Dim drNewItemCost As DataRow<br />
<br />
drNewItemCost = dtItemCost.NewRow<br />
drNewItemCost.Item("PartNo") = "123"<br />
drNewItemCost.Item("Cost") = 10<br />
dtItemCost.Rows.Add(drNewItemCost)<br />
<br />
drNewItemCost = dtItemCost.NewRow<br />
drNewItemCost.Item("PartNo") = "100"<br />
drNewItemCost.Item("Cost") = 100<br />
dtItemCost.Rows.Add(drNewItemCost)<br />
<br />
drNewItemCost = dtItemCost.NewRow<br />
drNewItemCost.Item("PartNo") = "123"<br />
drNewItemCost.Item("Cost") = 30<br />
dtItemCost.Rows.Add(drNewItemCost)<br />
<br />
drNewItemCost = dtItemCost.NewRow<br />
drNewItemCost.Item("PartNo") = "100"<br />
drNewItemCost.Item("Cost") = 105<br />
dtItemCost.Rows.Add(drNewItemCost)<br />
<br />
Dim dblAvgCost As Double<br />
<br />
dblAvgCost = dtItemCost.Compute("Avg(Cost)", " PartNo = '123'")
I hope this will help u...:->
Regards,
Ritesh
|
|
|
|
|
Thank you so much Ritesh
Saved me a lot of time!!
Ritesh1234 wrote: Dim dblAvgCost As Double
dblAvgCost = dtItemCost.Compute("Avg(Cost)", " PartNo = '123'")
I did have to first check that there is actually at least one Item specified by the filter otherwise it throws an exception. (I assume if there are no rows, the Average function would be dividing by Zero - hence an error)
Thanks again - really helpfull
Cheers
Richard
|
|
|
|
|
Hello all,
This is my project: I've made a TreeView that displays a folder and all sub folders within it. I also have an AfterSelect sub (Shown below) that looks through the selected directory and displays any files in a ListView. All this works.
This is my problem: Although I have an imagelist that is connected to the ListView control, it doesn't show the pictures beside the items when they are listed. All I have is a blank space where the picture should be. And when I try to assign an image to an item through the designer it just ignors them. Probably cause everything I'm doing is through the code view not the designer view. The only thing I can think of is that I'm forgetting to code something to tell the listview to show the images. Can anyone help me out?
This is the only code I've written that touches the listview so far.
Private Sub tvwExplorer_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwExplorer.AfterSelect<br />
'Get reference to the selected node<br />
Dim dirInfo As DirectoryInfo = New DirectoryInfo(e.Node.FullPath)<br />
'Clear all the items in the listview<br />
lvwExplorer.Items.Clear()<br />
'Check if the Directory exist or not<br />
If (dirInfo.Exists) Then<br />
'Get reference to all the files<br />
Dim fileInfos As FileInfo() = dirInfo.GetFiles()<br />
'Add all the files to the ListView<br />
Dim info As FileInfo<br />
For Each info In fileInfos<br />
Dim item As ListViewItem = New ListViewItem<br />
item = lvwExplorer.Items.Add(info.Name)<br />
item.SubItems.Add(info.LastAccessTime.ToString())<br />
Next<br />
End If<br />
End Sub
|
|
|
|
|
Darshon wrote: Dim item As ListViewItem = New ListViewItem
item = lvwExplorer.Items.Add(info.Name)
This adds a listview item which does not have an image index. You need to build your list view item so that it contains an image index.
Darshon wrote: Dim item As ListViewItem = New ListViewItem
item = lvwExplorer.Items.Add(info.Name)
This makes no sense. You create a new one, then you throw it away to be replaced by the one returned by Add.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thank you Christian Graus for your comments. I'm fairly new at programing with VB could you give me an example of how you would fix this?
|
|
|
|
|
Nevermind! I got it to work. I downloaded an example project from this site and looked at how s/he assigned an imagelist to an listviewitem and I got it to work on mine. Thanks for your help.
|
|
|
|
|
No worries - I just got in and online, but I'm glad you found a solution
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Object reference not set to an instance of an object.
Dim MyConn As New SqlConnection(ConfigurationManager.ConnectionStrings("psmConnectionString").ConnectionString)
how to solve it?
|
|
|
|
|
Well, at a guess you need to add psmConnectionString to your config file.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
i did put it on the config file.this is the line:
appSettings
add key="psmConnectionString" value="Provider=.NET Framework Data Provider for SQL Server:Data Source=HAPPYFAM-B614E1\SQLEXPRESS;Initial Catalog=psm;Integrated Security=True" appSettings
is it rite?
-- modified at 2:49 Thursday 23rd February, 2006
|
|
|
|
|
>>Dim MyConn As New SqlConnection(ConfigurationManager.ConnectionStrings("psmConnectionString").ConnectionString)
What makes you think that the psmConnectionString item in the config manager will have a connection string property ? Why is it in the ConnectionStrings collection ? I didn't know there was such a thing, but assuming that there is, I'd assume that you need to do something specific to get your config item to appear there.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|