i've a problem with de ScrollBar in VB6. Watch de next gif:
How can I solve that?
Here's my all code:
Option Explicit
Private old Post As Integer
Dim index As Integer
Dim indicee As Integer
Public Disclaimer
Private Sub btnAdd_Click ()
index = index + 1 'we increase the index
indicee = indicee + 0 'we start it at 0
pic1 (indicee) .Visible = True
'Label and TextBox type
lblType (indicee) .Visible = True
cmbAddType (indicee) .Visible = True
'Label and TextBox prefix
lblAddPrefix (indicee) .Visible = True
txtAddPrefix (indicee) .Visible = True
'Number Label and TextBox
lblAddNum (indicee) .Visible = True
txtAddNumber (indicee) .Visible = True
chkAddPrincipal (indicee) .Visible = True
'Label and TextBox link
lblAddVin (indicee) .Visible = True
cmbAdd Link (indicee) .Visible = True
'uc1
Load pic1 (index) 'we create the control
pic1 (index) .Visible = True 'we make it visible
pic1 (index) .Top = pic1 (index - 1) .Top + pic1 (index - 1) .Height + 20
'lblType
Load lblType (index)
Set lblType (index) .Container = pic1 (index)
lblType (index) .Visible = True
lblType (index) .Top = lblType (index - 1) .Top
'cmbAddType
Load cmbAddType (index)
Set cmbAddType (index) .Container = pic1 (index)
cmbAddType (index) .Visible = True
cmbAddType (index) .Top = cmbAddTipo (index - 1) .Top
'lblAddPrefix
Load lblAddPrefix (index)
Set lblAddPrefix (index) .Container = pic1 (index)
lblAddPrefix (index) .Visible = True
lblAddPrefix (index) .Top = lblAddPrefix (index - 1) .Top
'txtAddPrefix
Load txtAddPrefix (index)
Set txtAddPrefix (index) .Container = pic1 (index)
txtAddPrefix (index) .Visible = True
txtAddPrefix (index) .Top = txtAddPrefix (index - 1) .Top
'lblAddNum
Load lblAddNum (index)
Set lblAddNum (index) .Container = pic1 (index)
lblAddNum (index) .Visible = True
lblAddNum (index) .Top = lblAddNum (index - 1) .Top
'txtAddNumber
Load txtAddNumber (index)
Set txtAddNumber (index) .Container = pic1 (index)
txtAddNumber (index) .Visible = True
txtAddNumber (index) .Top = txtAddNumber (index - 1) .Top
'checkAddPrincipal
Load chkAddPrincipal (index)
Set chkAddPrincipal (index) .Container = pic1 (index)
chkAddPrincipal (index) .Visible = True
chkAddPrincipal (index) .Top = chkAddPrincipal (index - 1) .Top
'lblAddVin
Load lblAddVin (index)
Set lblAddVin (index) .Container = pic1 (index)
lblAddVin (index) .Visible = True
lblAddVin (index) .Top = lblAddVin (index - 1) .Top
'cmbAdd Link
Load cmbAdd Link (index)
Set cmbAdd Link (index) .Container = pic1 (index)
cmbAdd Link (index) .Visible = True
cmbAddLink (index) .Top = cmbAddLink (index - 1) .Top
End Sub
Private Sub Form_Load ()
scrollAdd.Min = 0
scrollAdd.Max = 1000
scrollAdd.SmallChange = Screen.TwipsPerPixelX * 10
scrollAdd.LargeChange = scrollAdd.SmallChange
End Sub
Private Sub scrollAdd_Change ()
ScrollPictureBox
End Sub
Private Sub scrollAdd_Scroll ()
ScrollPictureBox
End Sub
Private Sub ScrollPictureBox ()
Dim c As Control
For Each c In Me.Controls
If c.Container.Name = "pic1" And Not TypeOf c Is VScrollBar Then
c.Top = c.Top + (oldPos - scrollAdd.Value)
End if
Next
oldPos = scrollAdd.Value
End Sub
Can anyone help me?
I need to solve that problem with the ScrollBar.
I need it to move correctly, how do I do it?
~I added gifs to you can understand my "bug/error"
My english is not good but i hope that you can understand
I want the scrollbar to move correctly without moving the form as seen in the gif. The idea is that when pressing the button, fields are added and with the ScrollBar they can be seen but as you will see the whole form moves including the ScrollBar~
What I need is that there is a ScrollBar that allows scrolling to see all the elements that are added each time the button is pressed.
Since this is your third question on this topic, I will present a complete and much simpler solution. The first step is to create a UserControl visually using the Designer. The result should look like this:
You then start building your main form. You can use the UserControl for both the top section and any additional instances you require. The form ends up looking like this:
The red circle shows a UserControl named uc1 with an Index of 0. The blue circle shows a VScrollBar control inside a PictureBox named Picture1. All additional UserControl's will also be placed inside the PictureBox. Now on to the code:
Option Explicit
Private index As Integer
Private oldPos As Integer
Private Sub Form_Load()
scrollAdd.Min = 0
scrollAdd.Max = 3000
scrollAdd.SmallChange = Screen.TwipsPerPixelX * 10
scrollAdd.LargeChange = scrollAdd.SmallChange
Picture1.Visible = False
End Sub
Private Sub scrollAdd_Change()
ScrollControls
End Sub
Private Sub scrollAdd_Scroll()
ScrollControls
End Sub
Private Sub btnAdd_Click()
index = index + 1
Load uc1(index)
Set uc1(index).Container = Picture1 'place the control inside the PictureBox
uc1(index).Visible = True
uc1(index).Top = IIf(index = 1, 0, uc1(index - 1).Top + uc1(index - 1).Height + 20)
Picture1.Visible = True
End Sub
Private Sub ScrollControls()
Dim c As Control
For Each c In Me.Controls
If c.Container.Name = "Picture1" And Not TypeOf c Is VScrollBar Then
c.Top = c.Top + (oldPos - scrollAdd.Value)
End If
Next
oldPos = scrollAdd.Value
End Sub
Notice how simple the code has become, in particular the Add event handler. It also works the way you need. At some point you will need to gain access to the state of a UserControl. What I typically do is define properties for the UserControl:
Option Explicit
Public Property Get AddType() As String
AddType = cmbAddType.Text
End Property
Public Property Let AddType(ByVal Value As String)
cmbAddType.Text = Value
End Property
Public Property Get AddPrefix() As String
AddPrefix = txtAddPrefix.Text
End Property
Public Property Let AddPrefix(ByVal Value As String)
txtAddPrefix.Text = Value
End Property
Public Property Get AddNumber() As String
AddNumber = txtAddNumber.Text
End Property
Public Property Let AddNumber(ByVal Value As String)
txtAddNumber.Text = Value
End Property
Public Property Get AddPrincipal() As Integer
AddPrincipal = chkAddPrincipal.Value
End Property
Public Property Let AddPrincipal(ByVal Value As Integer)
chkAddPrincipal.Value = Value
End Property
Public Property Get AddLink() As String
AddLink = cmbAddLink.Text
End Property
Public Property Let AddLink(ByVal Value As String)
cmbAddLink.Text = Value
End Property
With the properties in place, you can now set and get the state of a UserControl using any valid index:
Private Sub TestTheScreen()
'you can initialize the controls as needed
uc1(0).AddPrefix = "My Prefix"
uc1(0).AddPrincipal = vbChecked
'and at some point retrieve the state
Dim ap As Integer
ap = uc1(0).AddPrincipal
End Sub
Related
In my shiny app, I have a box with a dropdown menu in the top left corner. However, some of the elements in my box are being cut off by the dropwdown menu (for example, in the pic below the table in my box is being covered by the menu). Is there a way to have the menu to always stay above other elements in my box?
This is my code. I noticed this issue only occurs if I use rhandsontable to render my tables. Unfortunately, I do need to use rhandsontable.
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(rhandsontable)
factorUI <- function(id) {
ns <- NS(id)
box(
width=6,
title = "Charts",
closable = TRUE,
status = "danger",
solidHeader = TRUE,
collapsible = TRUE,
dropdown(
style = "material-circle",
selectInput(ns("options"),"Select an option:",
choices = list("All" = "all", "Option1" = "option1","Option2" = "option2"),selected = "all"),
conditionalPanel("input.options == 'option1'",ns=ns, sliderInput(ns("shr.month"),"No of months:",min=0,max=1,value=c(0,1),step = 1)),
conditionalPanel("input.options == 'option2'",ns=ns, sliderInput(ns("fh.month"),"No of months:",min=0,max=1,value=c(0,1),step = 1)),
conditionalPanel("input.manual == 'Y'",fileInput(ns("upload"),"Upload new pattern",accept = ".csv")),
materialSwitch(inputId = ns("factorind"),label = "Apply factor",status = "primary",right = TRUE),
conditionalPanel("input.factorind == true",ns=ns,
numericInput(ns("start"),"Apply from:",value = NULL,min=0,step=1),
numericInput(ns("factor"),"Factor:",value=NULL,min=0)),
id = ns("sidebar"),
status = "danger",
size = "sm",
icon = shiny::icon("sliders")),
rHandsontableOutput(ns("table")),
)
}
factor <- function(id) {(
moduleServer(
id,
function(input,output,session) {
output$table <- renderRHandsontable({
rhandsontable(iris)
})
}
)
)}
ui <- fluidPage(
titlePanel("Example"),
sidebarLayout(
sidebarPanel(),
mainPanel(factorUI("test"))
)
)
server <- function(input, output) {
factor("test")
}
shinyApp(ui = ui, server = server)
Increase the z-index of dropdown, you can add the style before the end of box like this:
box(
...,
tags$style('.sw-dropdown-content {z-index: 105;}')
)
The CSS z-index decides the layer order of elements, which one is on top which is below. The table has index of 102, so if you make a number larger than that one for your dropdown (shinyWidgets dropdown default is 5), your drop down will be on top.
Basically, I'm almost finished making this note app which the users save notes etc. Basic note app function. The reason I'm not fully done is that i just need help with adding tiles to my app for the notes. Basically the user clicks the "Pin to start" from the menu item and for the selected note, pins that to the start. I've done this through:
Private Sub PinToStart_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
Dim Storage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
Dim data As SampleData = TryCast(TryCast(sender, MenuItem).DataContext, SampleData)
Dim selectedItem As ListBoxItem = TryCast(Me.SavedNotesList.ItemContainerGenerator.ContainerFromItem(data), ListBoxItem)
Dim directory As String = "./MyNote/SavedNotes/*.*"
Dim filenames As String() = Storage.GetFileNames(directory)
Dim dataSource As New List(Of SampleData)()
For Each filename As String In filenames
Dim ISF As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
Dim FS As IsolatedStorageFileStream = ISF.OpenFile("MyNote/SavedNotes/" & filename, FileMode.Open, FileAccess.Read)
Dim FETime As String = Storage.GetCreationTime("MyNote/SavedNotes/" & data.FileNameX).ToString("dd/mm/yyyy h:mmtt")
Dim tileData As New StandardTileData() With { _
.Title = data.FileNameX, _
.BackgroundImage = New Uri("/Assets/202.png", UriKind.Relative), _
.BackTitle = data.FileNameX, _
.BackContent = data.Description}
ShellTile.Create(New Uri("/ViewPage.xaml?Title=" & data.FileNameX & "&Body=" & data.Description, UriKind.Relative), tileData)
Next
End Sub
Currently this is the code which creates the tile. Although there is one problem, once the tile is created it throws an exception and says "Tiles can only be created when the application is in the foreground" but it still proceeds and creates the tile with no problem. Second error i have is that I need a way to update the tile. I just don't know how.
Can anyone help me?
use HubTile control from Microsoft.Phone.Controls.Toolkit to created tile
you can try this code:
var shellTileData = new StandardTileData
{
BackgroundImage = new Uri("Path for image", UriKind.RelativeOrAbsolute),
BackContent = "xyz"
};
var tile = ShellTile.ActiveTiles.First();
tile.Update(shellTileData);
Okay so I'm using the below code to display the camera in my app and it works great! the problem is when i navigate away and come back to the app using the back stack the camera is not showing until i call the code manually.
how can i get it to show automatically ?
Thank Youuu in advance
Dim cam As New Microsoft.Devices.PhotoCamera()
Public Sub New()
InitializeComponent()
SupportedOrientations = SupportedPageOrientation.Portrait
End Sub
Private Sub opening() Handles Me.Loaded
cam = New Microsoft.Devices.PhotoCamera()
viewfinderBrush.RelativeTransform = New CompositeTransform() With {.CenterX = 0.5, .CenterY = 0.5, .Rotation = 90}
viewfinderBrush.SetSource(cam)
End Sub
Private Sub Closing() Handles Me.Unloaded
cam.Dispose()
End Sub
Fixed my Own Problem, just used protected overide subs :)
Like So
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
MyBase.OnNavigatedTo(e)
cam = New Microsoft.Devices.PhotoCamera()
viewfinderBrush.RelativeTransform = New CompositeTransform() With {.CenterX = 0.5, .CenterY = 0.5, .Rotation = 90}
viewfinderBrush.SetSource(cam)
End Sub
Protected Overrides Sub OnNavigatedFrom(e As NavigationEventArgs)
MyBase.OnNavigatedFrom(e)
If cam IsNot Nothing Then
cam.Dispose()
cam = Nothing
End If
End Sub
I have following code, which make scroll to specific child. It works fine except when scroll to the last child. It works OK but it's not my expect behavior.The PROBLEM is when scroll to last child, I want the child to show on the top of viewport just like other ones. Some diagrams should help this a little better than words ever could.
Summary the issue:
1.when scroll to last child, is it possible to position it at (0,0) in the viewport?
2.I have 6 children, each one has 200 height. The contentHeight is 1200. when the verticalScrollPosition is 0, I invoke the viewport.getVerticalScrollPositionDelta(NavigationUnit.END), the returned value
is 900. So how the 900 is calculated?
following is the code:
<?xml version="1.0" encoding="utf-8"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="init()"
>
<fx:Script>
<![CDATA[
import components.MockUI;
import mx.collections.ArrayList;
import spark.core.NavigationUnit;
private function init():void {
createElements();
}
private function createElements():void {
for (var i:int = 0; i<6; i++) {
var ui:MockUI = new MockUI();
ui.text = "I'm " + i + " !";
ui.width = 300;
ui.height = 200;
viewport.addElement(ui);
}
}
//scroll to diffrent child, take attetion to the scrollRect
private function scrollToChild(index:int):void {
var delta:Number = returnSumHeight(index);
viewport.verticalScrollPosition = delta;
var scrollRect:Rectangle = viewport.scrollRect;
trace("viewport contentHeight: ", viewport.contentHeight);
trace("vp: ", viewport.verticalScrollPosition);
trace("scrollRect: ", scrollRect);
}
private function handleScroll(unit:uint):void {
trace("unit: ", unit);
var delta:Number = viewport.getVerticalScrollPositionDelta(unit);
trace("delta:", delta);
}
private function minus():void {
viewport.verticalScrollPosition -= 10;
trace("vp: ", viewport.verticalScrollPosition);
}
//return the sum height of children before index item
private function returnSumHeight(index:int):Number {
var sumHeight:Number = 0;
for(var i:int=0; i<index; i++) {
sumHeight += viewport.getElementAt(i).height;
}
return sumHeight;
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout horizontalAlign="center" paddingTop="100"/>
</s:layout>
<s:HGroup>
<s:Label text="Select Child: "/>
<s:ComboBox id="comboBox"
dataProvider="{new ArrayList([0,1,2,3,4,5])}"
selectedIndex="0"
change="scrollToChild(comboBox.selectedIndex)"/>
</s:HGroup>
<s:Scroller>
<s:VGroup id="viewport" width="350" height="300" gap="0">
</s:VGroup>
</s:Scroller>
<s:Button label="MINUS" click="minus()"/>
<s:Button label="UP" click="handleScroll(NavigationUnit.UP)"/>
<s:Button label="DOWN" click="handleScroll(NavigationUnit.DOWN)"/>
<s:Button label="HOME" click="handleScroll(NavigationUnit.HOME)"/>
<s:Button label="END" click="handleScroll(NavigationUnit.END)"/>
</s:Application>
MOCKUI:
package components {
public class MockUI extends UIComponent {
private var label:Label;
private var _text:String;
private var textChanged:Boolean = false;
public function set text(value:String):void {
if(value == _text) {
return;
}
_text = value;
textChanged = true;
invalidateProperties();
}
public function get text():String {
return _text;
}
override protected function createChildren():void {
super.createChildren();
label = new Label();
addChild(label);
}
override protected function commitProperties():void {
super.commitProperties();
if(textChanged) {
textChanged = false;
label.text = _text;
}
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
label.width = unscaledWidth/2.0;
label.height = unscaledHeight/2.0;
label.x = unscaledWidth/2.0;
label.y = unscaledHeight/2.0;
graphics.clear();
graphics.lineStyle(2, 0xffff00);
graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
graphics.beginFill(0xff0000, 1);
graphics.drawRect(0,0,unscaledWidth, unscaledHeight);
graphics.endFill();
}
}
}
When scrolling to last child, is it possible to position it at (0,0) in the viewport?
No, it's not possible with the default code in the Flex SDK and due to the size of your viewport/elements. The only way to make that happen with the default code is to make your viewport the same size as one item (and all items have the same height).
The Scroller won't allow you to scroll past the end of the content (except as an effect in mobile apps). You could extend the Scroller class to allow this.
I have 6 children, each one has 200 height. The contentHeight is 1200. when the verticalScrollPosition is 0, I invoke the viewport.getVerticalScrollPositionDelta(NavigationUnit.END), the returned value is 900. So how the 900 is calculated?
The height of each child is 200, but the height of the container they are in is 300 pixels. Because the scroller won't allow you to scroll past the end of the content, it restricts the max value of scroll position to: contentHeight - viewportHeight (1200 - 300 = 900).
Think of the viewport as something that moves (in this case) vertically over the content. The content is 1200 pixels tall, but since the viewport is 300 pixels, we never need to set the viewport's Y position above 900 pixels to see the end of the content.
I have implemented a function with that i have added a view with the some button as well as added Eventlistener .
with the button listener i transitioned to another view and removed the last view but still the button listener is active .
function loadingMenu()
playBtn = display.newImage('play-btn.png', 170, 130)
playBtn:addEventListener( "tap", listener )
instructionBtn = display.newImage('instructions-btn.png', 150, 164)
-- instructionBtn:addEventListener( "tap", instructionListener )
creditBtn = display.newImage('credits-btn.png', 180, 201)
--creditBtn:addEventListener( "tap",ceditsListener )
titleBg = display.newImage('background-with-title.png')
--titleView = display:newGroup()
titleView = display.newGroup(titleBg, playBtn, instructionBtn,creditBtn)
end
function listener(event)
if titleView ~= nil then
playBtn:removeEventListener( "tap", listener )
transition.to(titleView, {time = 300, y = -titleView.width, onComplete = function() --startButtonListeners('rmv') --titleView:removeSelf() display.remove(titleView) titleView = nil end})
end
return true
end
Thanks in advance
Try this. This will work...
----------------------------------------------------------------------------
local playBtn,instructionBtn,creditBtn,titleBg,titleView
----------------------------------------------------------------------------
function newfunction()
print("inside newfunction...")
end
----------------------------------------------------------------------------
function listener()
print("inside listener...")
if titleView ~= nil then
playBtn:removeEventListener( "tap", listener )
transition.to(titleView, {time = 300, y = -titleView.width, onComplete = newfunction()}) --startButtonListeners('rmv') --titleView:removeSelf() display.remove(titleView) titleView = nil end})
end
return true
end
----------------------------------------------------------------------------
function loadingMenu()
playBtn = display.newImage("play-btn.png", 170, 130)
instructionBtn = display.newImage("instructions-btn.png", 150, 164)
creditBtn = display.newImage("credits-btn.png", 180, 201)
titleBg = display.newImage("background-with-title.png")
titleView = display.newGroup(titleBg, playBtn, instructionBtn,creditBtn)
playBtn:addEventListener( "tap", listener )
end
----------------------------------------------------------------------------
loadingMenu()
----------------------------------------------------------------------------