|
Did you test the code...?
Well... Because the above didn't work for me. I made a test project to see how it works. but it didn't show me any message...
|
|
|
|
|
Did you recalculate the max value of your scrollbar? if your listbox is of a differed size then mine (witch it probably is) you have to recalculate it.
just run the program. dont scroll and see how many items fit into the listbox (for me that where 18). you want to do the index - [the number you found]. after that it should work.
maxscroll = index - 18
|
|
|
|
|
Oh that kinda worked... but how am I ganna calculate the value in a control like this one:
When its normal screen size:
http://foto.pk/images/minx.png[^]
When its maximized:
http://foto.pk/images/maxx.png[^]
-------------------------------------------------------------
Btw. You asked why would I want to know this value before...
Answer) I don't actually want to show users "yay u reached the bottom" lol. I want the program to get more tweets when it reaches there.
The above that I am making is a v2 of my current twitter client called TRocket.
TRocket - Twitter Client [Open Source][^]
|
|
|
|
|
How do you fill the listbox? with a loop or a data binding?
EDIT:
oke something just shot to my mind. the items you add to your listbox are controls right? i forgot the object name but i've seen the code of those. this means they have a fixed sized right? you could calculate how much fit into your listbox if you read out the length and hight of it.
lets say for example your listbox is 300 pixels wide and 400 pixels high. your controls are 100 wide and 50 high. this would mean you can fit 3 rows of each 8 items = 24 items without scroll bar. so in a 'math' way:
[ammount of items] - (math.floor([with_listbox]/[with_control])+math.floor([hight_listbox]/[hight_control])) = maximum scroll value
-------------------
Ah oke, yea now its making sense and i already figured it was for Trocket (read the thread about it) when i was helping you with a previous question.
|
|
|
|
|
|
Private Function CalculateMaxScrollValue(ByVal totalitems As Int64, ByVal controlhight As Int32, ByVal controlwith As Int32)
Return totalitems - (Math.Floor(controlwith / 482) * Math.Floor(controlhight / 114))
End Function
Add that function to your code to find the max scroll value.
Use that in combination with the code i send you in the previous posts in this topic. replace the txtscroll with the flowlayoutpanel1 and it should work (cant test it here).
as a side note: you might want to fine tune the if/else of mine a little to a "<" instead of "=". giving a exact value to a 'analog' control gives it a small change to trigger. also it seems like the program is single threaded. i don't know how long it takes to load those messages but your interface will hang (not responding ect) till the load is complete. looking into threading might be interesting.
|
|
|
|
|
Err my laptops fan got fried - is at the repair shop. - sorry for the late reply...
Anyway. So you mean I should just call this function on load? and replace the maxscroll = index - 18 on load?
|
|
|
|
|
Hey,
Sorry for my late response. I unfortunately fell ill.
to get back to your question: No, you call that function every time after the amount of items in your flowlayoutpanel changes.
|
|
|
|
|
so all the code needs to be same. but what should I do with:
maxscroll = index - 18 ?
the index property was giving an error in flowlayoutpanel. can you give me the example on the same code
or better on the project its self.. :
Imports System.Runtime.InteropServices
Public Class Form1
Dim WithEvents scrollhandler As MyListener
Private scrolled As Boolean = False
Private maxscroll As Int64
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function GetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer) As Integer
End Function
<DllImport("user32.dll")> _
Private Shared Function SetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer, ByVal nPos As Integer, ByVal bRedraw As Boolean) As Integer
End Function
Private Const SB_HORZ As Integer = &H0
Private Const SB_VERT As Integer = &H1
Public Property HScrollPos() As Integer
Get
Return GetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB_HORZ)
End Get
Set(ByVal value As Integer)
SetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB_HORZ, value, True)
End Set
End Property
Public Property VScrollPos() As Integer
Get
Return GetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB_VERT)
End Get
Set(ByVal value As Integer)
SetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB_VERT, value, True)
End Set
End Property
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim index As Int32 = 0
Do While index < 1000
txtscroll.Items.Add(index.ToString())
index += 1
Loop
maxscroll = index - 18
scrollhandler = New MyListener(txtscroll)
End Sub
Private Sub scrollhandler_MyScroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles scrollhandler.MyScroll
If VScrollPos = maxscroll And scrolled Then
MessageBox.Show("you reached the max on the verticle scrollbar!", "yay")
scrolled = False
ElseIf VScrollPos < maxscroll Then
scrolled = True
End If
End Sub
Private Sub txtscroll_MouseWheelScroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtscroll.MouseWheel
scrollhandler_MyScroll(e, e)
End Sub
Private Class MyListener
Inherits NativeWindow
Public Event MyScroll(ByVal sender As Object, ByVal e As EventArgs)
Const WM_MOUSEACTIVATE = &H21
Const WM_MOUSEMOVE = &H200
Private control As Control
Public Sub New(ByVal control As Control)
AssignHandle(control.Handle)
End Sub
Protected Overrides Sub WndProc(ByRef Messageevent As Message)
Const WM_HSCROLL = &H114
Const WM_VSCROLL = &H115
If Messageevent.Msg = WM_HSCROLL Or Messageevent.Msg = WM_VSCROLL Then
RaiseEvent MyScroll(control, New EventArgs)
End If
MyBase.WndProc(Messageevent)
End Sub
Protected Overrides Sub Finalize()
ReleaseHandle()
MyBase.Finalize()
End Sub
End Class
End Class
|
|
|
|
|
hmm oke i admid my code was a bit of mess. i cleared it out a bit and made a example program so you can see how it works. Please follow the below steps.
1. start a new form project
2. Add is Listbox. set the name to txtscroll and the size to 254; 381
3. Add a button, call this one btnadd
4. copy paste the following code into the project (under the form you just made)
Imports System.Runtime.InteropServices
Public Class Form1
#Region "declarations"
Dim WithEvents scrollhandler As MyListener
Private scrolled As Boolean = False
Private maxscroll As Int64
Private index As Int32 = 0
Private Const SB_HORZ As Integer = &H0
Private Const SB_VERT As Integer = &H1
#End Region
#Region "dll calls"
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function GetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer) As Integer
End Function
<DllImport("user32.dll")> _
Private Shared Function SetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer, ByVal nPos As Integer, ByVal bRedraw As Boolean) As Integer
End Function
#End Region
Public Property HScrollPos() As Integer
Get
Return GetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB_HORZ)
End Get
Set(ByVal value As Integer)
SetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB_HORZ, value, True)
End Set
End Property
Public Property VScrollPos() As Integer
Get
Return GetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB_VERT)
End Get
Set(ByVal value As Integer)
SetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB_VERT, value, True)
End Set
End Property
#Region "form events"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Do While index < 1000
txtscroll.Items.Add(index.ToString())
index += 1
Loop
scrollhandler = New MyListener(txtscroll)
maxscroll = CalcMaxScroll(txtscroll.Size.Height, txtscroll.Size.Width, 13, 254, txtscroll.Items.Count)
End Sub
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
Dim i As Int32 = index
Do While i < index + 10
txtscroll.Items.Add((index + i).ToString())
i += 1
Loop
index += 10
maxscroll = CalcMaxScroll(txtscroll.Size.Height, txtscroll.Size.Width, 13, 254, txtscroll.Items.Count)
End Sub
Private Sub txtscroll_MouseWheelScroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtscroll.MouseWheel
scrollhandler_MyScroll(e, e)
End Sub
Private Sub scrollhandler_MyScroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles scrollhandler.MyScroll
If VScrollPos = maxscroll And scrolled Then
MessageBox.Show("you reached the max on the verticle scrollbar!", "yay")
scrolled = False
ElseIf VScrollPos < maxscroll Then
scrolled = True
End If
End Sub
#End Region
#Region "calculations"
Private Function CalcMaxScroll(ByVal controlhight As Int32, ByVal controlwith As Int32, ByVal itemhight As Int32, ByVal itemwith As Int32, ByVal totalitems As Int32)
Return totalitems - (Math.Floor(controlwith / itemwith) * Math.Floor(controlhight / itemhight))
End Function
#End Region
#Region "native scroll listner"
Private Class MyListener
Inherits NativeWindow
Public Event MyScroll(ByVal sender As Object, ByVal e As EventArgs)
Const WM_MOUSEACTIVATE = &H21
Const WM_MOUSEMOVE = &H200
Private control As Control
Public Sub New(ByVal control As Control)
AssignHandle(control.Handle)
End Sub
Protected Overrides Sub WndProc(ByRef Messageevent As Message)
Const WM_HSCROLL = &H114
Const WM_VSCROLL = &H115
If Messageevent.Msg = WM_HSCROLL Or Messageevent.Msg = WM_VSCROLL Then
RaiseEvent MyScroll(control, New EventArgs)
End If
MyBase.WndProc(Messageevent)
End Sub
Protected Overrides Sub Finalize()
ReleaseHandle()
MyBase.Finalize()
End Sub
End Class
#End Region
End Class
5. run it scroll all the way down, hit the button and scroll down again.
oke now how does it work:
I explained the working of the scroll handlers before so to save some text i'll skip past those in here. the interesting part is in the button klick event. the first few lines is a random loop that will add 10 extra items to my listbox. i gues thats not to interesting, the line following after is.
It will set the maxscroll value to the return of the CalcMaxScroll sub. this sub requires you to give it the following information: The height property of your control. The With property of your control. the Height of the item you send to it (a listbox row is 13 high by default). the With of the item you send to it (in a listbox thats the full with). and the total ammount of items in the listbox. it will return you the maximum scroll position of your scrollbar.
Tought i now use this function with a listbox (i was to lazy to make a new project) it will work perfectly fine aswell with a flowlayout panel. just remember to send all the info to the function and that all the items in the box are the same size. if they aint the same size calculating will get a little harder....but not impossible.
ps: just put a breakpoint on the button klick event and watch what happends after the loop. keep the breakpoint on and scroll a bit. things get pretty clear once you see it running.
|
|
|
|
|
Alright so here is what I got so far:
Dim WithEvents scrollhandler As MyListener
Private scrolled As Boolean = False
Private maxscroll As Int64
Private Const SB_HORZ As Integer = &H0
Private Const SB_VERT As Integer = &H1
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function GetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer) As Integer
End Function
<DllImport("user32.dll")> _
Private Shared Function SetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer, ByVal nPos As Integer, ByVal bRedraw As Boolean) As Integer
End Function
Public Property HScrollPos() As Integer
Get
Return GetScrollPos(DirectCast(FlowLayoutPanel1.Handle, IntPtr), SB_HORZ)
End Get
Set(ByVal value As Integer)
SetScrollPos(DirectCast(FlowLayoutPanel1.Handle, IntPtr), SB_HORZ, value, True)
End Set
End Property
Public Property VScrollPos() As Integer
Get
Return GetScrollPos(DirectCast(FlowLayoutPanel1.Handle, IntPtr), SB_VERT)
End Get
Set(ByVal value As Integer)
SetScrollPos(DirectCast(FlowLayoutPanel1.Handle, IntPtr), SB_VERT, value, True)
End Set
End Property
Private Sub FlowLayoutPanel1_MouseWheelScroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FlowLayoutPanel1.MouseWheel
scrollhandler_MyScroll(e, e)
End Sub
Private Sub scrollhandler_MyScroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles scrollhandler.MyScroll
If VScrollPos = maxscroll And scrolled Then
MessageBox.Show("you reached the max on the verticle scrollbar!", "yay")
scrolled = False
ElseIf VScrollPos < maxscroll Then
scrolled = True
End If
End Sub
Private Function CalcMaxScroll(ByVal controlhight As Int32, ByVal controlwith As Int32, ByVal itemhight As Int32, ByVal itemwith As Int32, ByVal totalitems As Int32)
Return totalitems - (Math.Floor(controlwith / itemwith) * Math.Floor(controlhight / itemhight))
End Function
Private Class MyListener
Inherits NativeWindow
Public Event MyScroll(ByVal sender As Object, ByVal e As EventArgs)
Const WM_MOUSEACTIVATE = &H21
Const WM_MOUSEMOVE = &H200
Private control As Control
Public Sub New(ByVal control As Control)
AssignHandle(control.Handle)
End Sub
Protected Overrides Sub WndProc(ByRef Messageevent As Message)
Const WM_HSCROLL = &H114
Const WM_VSCROLL = &H115
If Messageevent.Msg = WM_HSCROLL Or Messageevent.Msg = WM_VSCROLL Then
RaiseEvent MyScroll(control, New EventArgs)
End If
MyBase.WndProc(Messageevent)
End Sub
Protected Overrides Sub Finalize()
ReleaseHandle()
MyBase.Finalize()
End Sub
End Class
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
scrollhandler = New MyListener(FlowLayoutPanel1)
maxscroll = CalcMaxScroll(FlowLayoutPanel1.Size.Height, FlowLayoutPanel1.Size.Width, 114, 1075, 19)
End Sub
Source code also attached:
http://www.mediafire.com/?m63ox9sllr887dd[^]
I am pretty sure I am doing everything right... but its just not working with flowlayoutpanel :/
|
|
|
|
|
It seems your making a mistake in providing the arguemnts for your max scroll.
Quote: Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
scrollhandler = New MyListener(FlowLayoutPanel1)
maxscroll = CalcMaxScroll(FlowLayoutPanel1.Size.Height, FlowLayoutPanel1.Size.Width, 114, 1075, 19)
'19 number of tweets
'114 height of tweettimelinecontrol
'1075 width of flowlayoutpanel1
'last number tells the number of items. (read that from a global var)
End Sub
You say that the with of your flowlayoutpanel is 1075. yet you apply it to the formula as the with of your tweettimelinecontrol. quoting you from a previous post:
Quote:
Oh that kinda worked... but how am I ganna calculate the value in a control like this one:
When its normal screen size:
http://foto.pk/images/minx.png[^]
you can see in the screenshot that you got 2 of those controls next to eachoter so it can never be the total size of your flowlayoutpanel. please check the with property of your Tweettimelinecontrol and change the value. while your at it also change the 19 with a flowlayoutpanel.items.count to make sure it are 19.
|
|
|
|
|
private int previousValue;
public void someEventHandler(...) {
int currentValue=...;
if (currentValue==extremeValue && currentValue!=previousValue) doWhatEver();
previousValue=currentValue;
}
|
|
|
|
|
oeh quite nice! might actually try that in the future. but isn't that C#?
|
|
|
|
|
I'd call it pseudo-code around here
|
|
|
|
|
1-0 for you
|
|
|
|
|
isn't previousValue a readonly value?
|
|
|
|
|
did I declare it read-only?
|
|
|
|
|
Seems like I misunderstood the algorithm.
|
|
|
|
|
Hi everyone,
I am currently working on developing some code for transfer file from one pc to another. As I read in lot of article, those work can be done by FTP concept.
I'm using win7 and VB.NET 2010
I've got some simple source code for uploading a file, but I'm experiencing a problem which describe below
System.ArgumentNullException was unhandled
Message=Value cannot be null.
Parameter name: type
ParamName=type
Source=mscorlib
it's refers to:
ITCObject = Activator.CreateInstance(ITC)
Here are the source code:
Imports System.IO
Imports System.Reflection
Imports System.Threading
Public Class Main
Private Sub btnBrowse_Click(ByVal sender As System.Object, e As System.EventArgs) Handles btnBrowse.Click
OpenFileDialog.ShowDialog()
tbFile.Text = OpenFileDialog.FileName
End Sub
Private Sub btnUpload_Click(ByVal sender As System.Object, e As System.EventArgs) Handles btnUpload.Click
Dim thisFile As FileInfo = New FileInfo(tbFile.Text)
Dim ITC As Type
Dim parameter() As Object = New Object(1) {}
Dim ITCObject As Object
ITC = Type.GetTypeFromProgID("InetCtls.Inet")
ITCObject = Activator.CreateInstance(ITC)
parameter(0) = CType(tbRemoteServer.Text, String)
parameter(1) = CType("PUT " + thisFile.FullName + " /" + thisFile.Name, String)
ITC.InvokeMember("execute", BindingFlags.InvokeMethod, Nothing, ITCObject, parameter)
End Sub
End Class
is there anyone could help me to resolve this problem.
Thx,
Phann
|
|
|
|
|
That means:
ITC = Type.GetTypeFromProgID("InetCtls.Inet")
returned null.
But tell us: why do you need Refelection for FTP?
|
|
|
|
|
what do you mean by Bernhard Hiller wrote: Refelection for FTP?
|
|
|
|
|
I'm really not quite sure.. but it came with the source code.. and it has related with "BindingFlags.InvokeMethod".
I'm still having difficulty to figure out the source code and how it works..
|
|
|
|
|
Compare your code with the sample here[^].
Bastard Programmer from Hell
|
|
|
|
|
|