How to copy selected item style to another item in Solid Edge? - vb.net

I'm developing a macro for Solid Edge which is stores values of things like font size, width etc. and applies them to another object. Both functions are executable by button click. First button is saving the property values and second applies them to another object. The problem is that I have no clue which methods or functions should I use to store the values.
Public Class Form1
Dim solidedge As SolidEdge.Framework.Interop.Application
Dim line As SolidEdge.Framework.Interop.SelectSet
Dim item As SolidEdge.FrameworkSupport.Interop.Line2d
Dim style As SolidEdge.FrameworkSupport.Interop.GeometryStyle2d
Dim breite As Double
Dim dashname As String
Dim autophase As Boolean
Dim dashgapcount As Integer
Dim dashstrokepercent As Double
Dim color As Integer
Dim linearname As String
Dim units As Integer
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
solidedge = GetObject(, "SolidEdge.Application")
line = solidedge.ActiveSelectSet
item = line.Item(1)
style = item.Style
breite = style.Width
autophase = style.AutoPhase
dashgapcount = style.DashGapCount
dashstrokepercent = style.DashStrokePercent
color = style.LinearColor
linearname = style.LinearName
units = style.Units
dashname = style.DashName
End Sub
End Class
Example: I want make the black line look like the pink line by copying format:

I am not familiar with Solid Edge, but based on the code you posted, you could try something like this:
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
solidedge = GetObject(, "SolidEdge.Application")
line = solidedge.ActiveSelectSet
item = line.Item(2)
item.Style = style
End Sub

Related

How do I fix this multidimensional array?

So I need to make a program that displays the monthly sales and totals of three different areas of a company when I click a button. I've added this code, but can't seem to get it right. Can someone advise me on how to fix it. Also, my headings "province, Percentage, Contribution etc" does not display in the list box when the form is loaded.
So basically the values in my .txt files are as follows:
1,Kwazulu Natal,44,120000
1,Gauteng,33,900000
1,Western Cape,23,65000
2,Kwazulu Natal,56,190000
2,Gauteng,25,85000
2,Western Cape,19,64000
3,Kwazulu Natal,54,175000
3,Gauteng,25,80000
3,Western Cape,21,71000
4,Kwazulu Natal,55,188000
4,Gauteng,25,83000
4,Western Cape,20,67000
5,Kwazulu Natal,46,125000
5,Gauteng,31,87000
5,Western Cape,23,65000
6,Kwazulu Natal,53,163000
6,Gauteng,26,80000
6,Western Cape,21,64000
Now they are supposed to show underneath their headings per month (1 - 6). When I run my code, they do not show headings, just the names of the places. It does not give errors
Imports System.IO
Public Class FormMain
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
resultsBox.Items.Clear()
resultsBox.Columns.Add("Province", 100, HorizontalAlignment.Center)
resultsBox.Columns.Add("Percentage", 100, HorizontalAlignment.Center)
resultsBox.Columns.Add("Contribution", 100, HorizontalAlignment.Center)
resultsBox.Columns.Add("Total Cost", 100, HorizontalAlignment.Center)
End Sub
Private Sub ExitBtn_Click(sender As Object, e As EventArgs) Handles ExitBtn.Click
Me.Close()
End Sub
Private Sub ShowResultsBtn_Click(sender As Object, e As EventArgs) Handles ShowResultsBtn.Click
Dim salesReport As String = MonthlyCBox.Text
Dim filereader As New StreamReader("C:\Users\HP Notebook 15\Desktop\main.txt")
Dim details As Array
Dim provinceFound As String = " "
Dim percentageContribute As Integer = 0
Dim monthlySales As Integer = 0
Dim totalvalue As Integer = 0
While filereader.EndOfStream = False
details = filereader.ReadLine().Split(",")
Dim province As String = details(1)
Dim percentage As Decimal = details(2)
Dim monthlyammount As String = details(3)
Dim totalamm As String = details(3)
If details(0) = salesReport Then
resultsBox.Items.Add(New ListViewItem({province, percentage, FormatCurrency(monthlyammount), FormatCurrency(totalamm)}))
End If
End While
End Sub
End Class
I guess you are using ListView, Not List Box. If so, please add
resultsBox.View = View.Details, in load event. That should visible the header text.

Button Array - how to pass a parameter to shared handler

I have a bit of code where i have a dynamically created array or buttons with staff pictures on them, as well as the staff's name. I've added one handler to handle any button click from any of the buttons. where i am stuck is, if you look at the code below, it all works fine, and if you click any of the buttons you get the "aha" test message. but i want the name of the staff clicked on (so btnArray(i).Text) to be passed to the handler for further processing. I tried adding a ByVal parameter to the handler but that caused an error. what's the correct way to do this? As i said, the code below works for me, i just am at a loss as to how to add the extra functionality.
Dim btnArray(staffcount) As System.Windows.Forms.Button
For i As Integer = 1 To staffcount - 1
btnArray(i) = New System.Windows.Forms.Button
btnArray(i).Visible = True
btnArray(i).Width = 80
btnArray(i).Height = 101
btnArray(i).BackgroundImage = Image.FromFile(picloc(i))
btnArray(i).BackgroundImageLayout = ImageLayout.Stretch
btnArray(i).Text = staffname(i)
Dim who As String
who = btnArray(i).Text
AddHandler btnArray(i).Click, AddressOf Me.theButton_Click
btnArray(i).ForeColor = Color.White
btnArray(i).TextAlign = ContentAlignment.BottomCenter
Dim fnt As Font
fnt = btnArray(i).Font
btnArray(i).Font = New Font(fnt.Name, 10, FontStyle.Bold)
FlowLayoutPanel1.Controls.Add(btnArray(i))
Next i
End Sub
Private Sub theButton_Click()
MsgBox("aha")
End Sub
First, correct the signature of your shared handler.
Private Sub theButton_Click(sender As Object, e As EventArgs)
End Sub
Once that is done getting the text of the button clicked is a simple matter.
Private Sub theButton_Click(sender As Object, e As EventArgs)
Dim textOfButtonClicked As String = DirectCast(sender, Button).Text
MessageBox.Show(textOfButtonClicked)
End Sub
The sender is the button that was clicked. Since signatures use objects for the sender the DirectCast 'changes' it to button and you then can access the .Text property of the button.
If there are more manipulations you want to perform on the clicked button you could do it this way
Private Sub theButton_Click(sender As Object, e As EventArgs)
Dim whBtn As Button = DirectCast(sender, Button) ' get reference to button clicked
Dim textOfButtonClicked As String = whBtn.Text
MessageBox.Show(textOfButtonClicked)
'e.g. change the color
whBtn.BackColor = Color.LightYellow
End Sub

detect when left mouse button is down while hovering over a button in Visual Basic.net

So I'm attempting to create a schedule grid in VB.net (exactly like the scheduler in UTorrent, if anyone is familiar) in a 24x7 layout. I want to be able to click down and drag over a series of squares to change the values of them.
I've been able to find this sample code that mostly works.
Private Sub DataGridView3_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView3.CellMouseMove
Dim grvScreenLocation As Point = DataGridView3.PointToScreen(DataGridView3.Location)
Dim tempX As Integer = DataGridView.MousePosition.X - grvScreenLocation.X + DataGridView3.Left
Dim tempY As Integer = DataGridView.MousePosition.Y - grvScreenLocation.Y + DataGridView3.Top
Dim hit As DataGridView.HitTestInfo = DataGridView3.HitTest(tempX, tempY)
cellX = hit.RowIndex
cellY = hit.ColumnIndex
TextBox3.Text = cellX
TextBox14.Text = cellY
End Sub
As written, this produces the desired results, however I need to have it only return cellx and celly to the text boxes only when the mouse button is down.
This can be accomplished by handling mouse left button down, mouse move and mouse left button up.
When you receive a mouse left button down event on the grid, record the mouse position and set a flag. In the mouse move handler if the flag is set, highlight all cells between the initial position and the current mouse position. On receiving a mouse left button up (on the grid when the grid is set) commit the cell selection (and clear the flag).
I've used this technique successfully for a fractal zoom.
Here's a rough outline of what you need to do:
Dim isSelecting As Boolean
Dim selectionStart As Point
Protected Overrides Sub OnMouseLeftButtonDown(e As MouseButtonEventArgs)
MyBase.OnMouseLeftButtonDown(e)
Dim position = e.GetPosition(Me)
Dim hit = VisualTreeHelper.HitTest(MyGrid, position)
If hit IsNot Nothing Then
isSelecting = True
selectionStart = position
End If
End Sub
Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
MyBase.OnMouseMove(e)
If isSelecting Then
Dim position = e.GetPosition(Me)
' Update selection
End If
End Sub
Protected Overrides Sub OnMouseLeftButtonUp(e As MouseButtonEventArgs)
MyBase.OnMouseLeftButtonUp(e)
If isSelecting Then
Dim position = e.GetPosition(Me)
' Commit selection
End If
End Sub
This gave me what I wanted.
Private cellX As Integer = 0
Private cellY As Integer = 0
Private Sub DataGridView3_MouseHover(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles DataGridView3.CellMouseMove
Dim grvScreenLocation As Point = DataGridView3.PointToScreen(DataGridView3.Location)
Dim tempX As Integer = DataGridView.MousePosition.X - grvScreenLocation.X + DataGridView3.Left
Dim tempY As Integer = DataGridView.MousePosition.Y - grvScreenLocation.Y + DataGridView3.Top
Dim hit As DataGridView.HitTestInfo = DataGridView3.HitTest(tempX, tempY)
cellX = hit.RowIndex
cellY = hit.ColumnIndex
If e.Button = Windows.Forms.MouseButtons.Left Then
TextBoxX.Text = cellX
TextBoxY.Text = cellY
DataGridView3.Rows(cellX).Cells(cellY).Style.BackColor = Color.Red
End If
End Sub

Back button in a vb.net program

I am trying to write the code for a back button in my VB.NET app. But it is not working. What is wrong with it?
Private Sub BackBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackBtn.Click
Dim returntext As String = Clipboard.GetText()
lblDictword.Text = returntext
Dim returnHtmlText As String = Nothing
If (Clipboard.ContainsText(TextDataFormat.UnicodeText)) Then
returnHtmlText = Clipboard.GetText(TextDataFormat.UnicodeText)
'Clipboard.SetText(replacementHtmlText, TextDataFormat.Html)
Clipboard.SetText(returnHtmlText, TextDataFormat.UnicodeText)
End If
lblDictword.Text = returnHtmlText
'Return returnHtmlText
Dim count As Integer = myStrings.Length
If count > 1 Then
Dim s As String = myStrings.ElementAt(count - xd)
xd = Array.IndexOf(myStrings, s)
lblDictword.Text = s
End If
End Sub
I am not an VB.NET expert, but usually getting access to clipboard isn't as easy as it looks. Check this:
Problem with clipboard class
It can be only a tip, not really solution. Look into your clipboard functionallity

Edit item or subitem values of a selected listview item

Ok, so I have a listview on one form, and when a button is pressed it opens up a new form with the contents of the selected listview item and it's subitems in a series of textboxes. The user can then change the data in the textboxes and either press save to make the changes or cancel to close the window.
What command would I use to change the selected listview item and subitems to whatever is in the boxes?
this is the code that populates the boxes:
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim appeditcontents As String = main.passlist.SelectedItems(0).ToString
Dim appstrlen As Integer = appeditcontents.Length()
Dim apptotal As Integer = appstrlen - 16
Dim usereditcontents As String = main.passlist.SelectedItems(0).SubItems(1).ToString
Dim userstrlen As Integer = usereditcontents.Length()
Dim usertotal As Integer = userstrlen - 19
Dim passeditcontents As String = main.passlist.SelectedItems(0).SubItems(2).ToString
Dim passstrlen As Integer = passeditcontents.Length()
Dim passtotal As Integer = passstrlen - 19
appedit.Enabled = False
appedit.Text = main.passlist.SelectedItems(0).ToString.Substring(15, apptotal)
useredit.Text = main.passlist.SelectedItems(0).SubItems(1).ToString.Substring(18, usertotal)
passedit.Text = main.passlist.SelectedItems(0).SubItems(2).ToString.Substring(18, passtotal)
End Sub
Any pointers on cleaning up this code would probably help too.
This page looks like it would help you.