Multiply your value by negative one, this will convert a positive to a negative and a negative to a positive. x *= -1
Karen Nooobie to OOP and VB.Net 2005
watagal
Posts
-
convert negative value to positive -
TableLayoutPanel in VB.Net 2005Thanks Dave, that got me past the error message. I still don't get a TableLayoutPanel Control on my at runtime, but I'll post a new message with an appropriate subject title. Thanks again, Karen Nooobie to OOP and VB.Net 2005
-
vb. nettry this:
lowestValue = Math.Min(Math.Min(value1,value2),value3)
and
highestValue = Math.Max(Math.Max(value1,value2),value3)
Thanks, Karen Nooobie to OOP and VB.Net 2005
-
TableLayoutPanel in VB.Net 2005I am trying to add a TableLayoutPanel (programatically). Here's what I have so far:
Private Sub drawTableLayoutPanel() Dim iColumns As Integer = uxColumnsTbar.Maximum ' Horizontal Trackbar Dim iRows As Integer = uxRowsTbar.Maximum ' Vertical Trackbar ' Dim oTLP As New TableLayoutPanel oTLP.Location = New Point(0, 0) oTLP.Size = New Size(500, 200) oTLP.AutoScroll = True oTLP.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink oTLP.GrowStyle = TableLayoutPanelGrowStyle.AddRows oTLP.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset ' oTLP.ColumnCount = iColumns For c As Integer = 0 To (iColumns - 1) oTLP.ColumnStyles(c).SizeType = SizeType.Absolute ' Errors HERE with c=0 oTLP.ColumnStyles(c).Width = (1 / iColumns) Next ' oTLP.RowCount = iRows For r As Integer = 0 To (iRows - 1) oTLP.RowStyles(r).SizeType = SizeType.Absolute oTLP.RowStyles(r).Height = (1 / iRows) Next ' oTLP.Update() End Sub
The error I get is:
System.ArgumentOutOfRangeException was unhandled
Message="Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"Which collection are they referring to? iColumns=6 and iRows=4 - this has been verified. Thanks, Karen Nooobie to OOP and VB.Net 2005
-
Code Review - comments welcomedHi all. I'm new at this and I'm looking for critical comments (on style too) so I can do it better the next time. I designed the following code trying to incorporate as many lessons as possible. Assumming my application consists of a main menu, a main toolstrip, and a main tabbed work area - I wanted an easy way to enable/disable main menu items or hide/display toolstrip button items --- depending on the current tab. My first attempt was a spider web of if statements. Then I decided on this approach - defining conditional (contextural) controls in a tabular fashion (getlistConditionalControls). Since some conditional controls may be disabled/hidden for several tabs, the 1st parameter is a bitwise sum of affected tabs. The 2nd parameter defines which property to affect (enabled or visible) - I would like to do away with this because I think I can test the referenced object (3rd parameter) for either ToolstripMenuItem or ToolstripButton. In my case all main menu items are enabled/disabled and toolstrip buttons are hidden/dislayed. Any help here? The last parameter is the alternate ToolTipText to inform the user as to why this control might be disabled (main menu items only). Only conditional controls need to be listed here. All comments and better ideas welcomed. Thanks
Public Class uxcMainFrm Private ConditionalControlItems As New ArrayList ' List of Conditional Controls Private Enum eProp As Integer enabled = 0 visible = 1 End Enum ' Private Sub uxcMainFrm_Load(....) Handles MyBase.Load Call getlistConditionalControls() ' Define Conditional Controls Call displayConditionalControls() ' Disable or Hide Controls Based on Cur Tab End Sub ' Private Sub uxcMainTabs_SelectedIndexChanged(....) Handles uxcMainTabs.SelectedIndexChanged Call displayConditionalControls() ' Disable or Hide Controls Based on Cur Tab End Sub ' Private Sub getlistConditionalControls() ' Toolstrip Buttons Call defineConditionalControl(6, eProp.visible, uxExpandBtn) ' Tabs #2 & #3 Call defineConditionalControl(3, eProp.visible, uxCollapseBtn) ' Tabs #1 & #2 ' .... and so on ' ' Main Menu Items Call defineConditionalControl(4, eProp.enabled, uxCreateMnuI, "To Enable: Select This or That") Call defineConditionalControl(6, eProp.enabled, uxRotateMnuI, "To Enable: Select This or That") ' .... and so on End Sub
-
Bitwise Enumeration? -
Bitwise Enumeration?Hi all, Not sure if my subject is correct in describing what I want to do. I have an integer variable (iOptions) where each bit represents an On/Off Flag: 0 = all off 1 = flag1 2 = flag2 4 = flag3 8 = flag4 ....... and so on Of course this integer variable could equal to 7 (flag1+flag2+flag3 are On) or anywhere in between. How do I write a bitwise if statement to check if anyone flag is On?
if iFlag1 ?? iOptions then ' **What goes here instead of ??** ... else if iFlag2 ?? iOptions then ... end if
Thanks, Karen Nooobie to OOP and VB.Net 2005 -
Invoking a Control by its Name string?Greetings! I want to switch controls (panels) visibility by using their respective names (in variables). How can I get there from here:
Public prefPanel As Panel = New Panel() Private Sub uxcPreferencesForm_Load(....) Handles MyBase.Load prefPanel = Me.uxcGeneralPnl ' Startup Panel prefPanel.Visible = True End Sub Private Sub uxCatagoryTree_AfterSelect(....) Handles uxCatagoryTree.AfterSelect prefPanel.Visible = False ' Hide Current Panel Dim path As String = uxCatagoryTree.SelectedNode.FullPath Dim arrPath As Array = path.Split("\") Dim panl As String = "uxc" ' Formulate new Panel's name For i As Integer = 0 To (arrPath.Length - 2) panl += arrPath(i).ToString.Substring(0, 3) Next i panl += arrPath(arrPath.Length - 1).ToString + "Pnl" prefPanel.Name = panl ' HERE IS WHERE I GET LOST prefPanel.Visible = True ' Show New Current Panel uxHeadingLbl.Text = panl 'path End Sub
The panels are all created (and designed) at compile time - they are invisible. Is there a way to handle this switching? Thanks, Karen Nooobie to OOP and VB.Net 2005
-
Designing a filmstrip?Greetings! I want to implement a filmstip in my application. I'm thinking of using a TableLayoutPanel as a container with a PictureBox in each cell. Is this how one with more experience do it? I've looked at TableLayoutPanel in the on-line help and searched for articles here - not much found. What general steps or required objects are required to dynamically add rows to a tablelayoutpanel at run time? This needs to be scrollable, show should I make the tablelayoutpanel scrollable or place the table in a scrollable panel? Thanks, Karen Nooobie to OOP and VB.Net 2005
-
How do you get the index of the currently selected item in a listview?Thanks all! I found it, just thought I'd pass it on.
uxFileLstvw.FocusedItem.Text
Thanks, Karen Nooobie to OOP and VB.Net 2005 -
[Message Deleted]Dave I took this challenge and found I'm having a tough time understang the logic flow of the object model. I get the circle to draw in the center of the PictureBox, but it is fleeting - it disappears as soon as it is drawn. I debugged only to find the circle vanishes as soon as I exit the Paint event on the PictureBox. Where am I failing?
Public Class Form1 Private _paper As Graphics Private _pen As Pen = New Pen(Color.Black, 3) Private Sub Form1_Load(....) Handles MyBase.Load _paper = Me.uxCanvasPicbx.CreateGraphics() End Sub Private Sub uxDiameterTrkbar_Scroll(....) Handles uxDiameterTrkbar.Scroll uxDiameterLbl.Text = uxDiameterTrkbar.Value.ToString uxCanvasPicbx.Invalidate() End Sub Private Sub uxCanvasPicbx_Paint(....) Handles uxCanvasPicbx.Paint Dim ul, lr As Integer lr = Me.uxDiameterTrkbar.Value ul = ((200 - lr) / 2) _paper.Clear(Color.White) _paper.DrawEllipse(_pen, ul, ul, lr, lr) End Sub End Class
Thanks, Karen Nooobie to OOP and VB.Net 2005 -
How do you get the index of the currently selected item in a listview?Greetings! me again. In a listview, how can I get the index # of the currently slected row? I see how to get a collection of selected items and a collection of checked items, but not the last selected item. It's been a long rainy day, help please. Thanks, Karen Nooobie to OOP and VB.Net 2005
-
More event troubles: SelectedIndexChangedGreetings!
Private Sub uxGpDirectoryTree_DoubleClick( _ ByVal sender As Object, ByVal e As System.EventArgs) _ Handles uxGpDirectoryTree.DoubleClick uxBaseDirCmbbx.Text += uxGpDirectoryTree.SelectedNode.Text + "\" End Sub
Everytime this code is invoked, it invokes another method (uxBaseDirCmbbx.SelectedIndexChanged) - except for the last subfolder. I assume this is because the Text property has changed. So why not on the last subfolder? Thanks, Karen Nooobie to OOP and VB.Net 2005 -
Event: Treeview-AfterSelectNot exactly what I wanted, but DoubleClick seams to work. Thanks, Karen Nooobie to OOP and VB.Net 2005
-
Event: Treeview-AfterSelectGreetings! I'm having trouble with my treeview. Once I select a node from the treeview, it invokes the AfterSelect event, re-fills my nodes and the re-executes the AfterSelect event (again) - thus re-filling my node tree:
Private Sub uxGpDirectoryTree_AfterSelect( _ ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) _ Handles uxGpDirectoryTree.AfterSelect Me.StartDir += uxGpDirectoryTree.SelectedNode.Text + "\" call fillDirectoryTree() End Sub Private Sub fillDirectoryTree() Dim arrSubfolders() As DirectoryInfo arrSubfolders = New DirectoryInfo(Me.StartDir).GetDirectories uxGpDirectoryTree.Nodes.Clear() For Each subfolder As DirectoryInfo In arrSubfolders uxGpDirectoryTree.Nodes.Add(subfolder.Name) Next End Sub
I have debugged and it does cycle more than once. Any help would be greatly appreciated. Thanks, Karen Nooobie to OOP and VB.Net 2005 -
How do you calc the absolute location of a control?Now that I have accomplished what I wanted to do, Is there a faster better easier way to do this somewhat common task? Thanks, Karen Nooobie to OOP and VB.Net 2005
-
How do you calc the absolute location of a control?watagal wrote: Greetings! If I have a control in a split-panel, which is in a tab control, which is in a form -- how can I obtain the absolute location of the original (button) control?
See non-working code in original post
X and Y are never incremented because o.Parent.Name always return "". Is there a better way (one that actually works) of trying to do this? Ok, figured out what was happening: The first parent above my button was a split panel, while the actual split panel returns the correct Name -- the Panel1 container within the split panel container does not return a Name (I guess because you can not assign it a name). Therefore, my while loop was never entered. Here's code that does work:Dim o As Control = uxLogPhotosToDbBtn Dim x As Integer = 0 Dim y As Integer = 0 While (Not o Is Nothing) x += o.Location.X y += o.Location.Y o = o.Parent End While Dim p1 As Point p1.X = x p1.Y = y uxcLogFotosForm.Show() uxcLogFotosForm.Location = p1
Thanks again for all the help, Thanks, Karen Nooobie to OOP and VB.Net 2005 -
How do you calc the absolute location of a control?I did try to debug it, it never enters the while loop -- even tho the control is buried in several levels of parent containers. Does o.Parent.Name return the parent's container's Name property? If not, what does? Thanks, Karen Nooobie to OOP and VB.Net 2005
-
Infinite loop - Resizing FormDooh! I promise to think next time before asking. No I'm not blond! Thanks to all!! Thanks, Karen Nooobie to OOP and VB.Net 2005
-
How do you calc the absolute location of a control?Greetings! If I have a control in a split-panel, which is in a tab control, which is in a form -- how can I obtain the absolute location of the original (button) control?
Dim o As Control = LogPhotosToDbBtn Dim x As Integer = LogPhotosToDbBtn.Location.X Dim y As Integer = LogPhotosToDbBtn.Location.Y While (o.Parent.Name <> "") o = o.Parent x += o.Location.X y += o.Location.Y End While Dim p1 As Point p1.X = x p1.Y = y LogFotosForm.Show() LogFotosForm.Location = p1
X and Y are never incremented because o.Parent.Name always return "". Is there a better way (one that actually works) of trying to do this? Thanks, Karen Nooobie to OOP and VB.Net 2005