Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Im trying to add two scroll bars to a form (through code not the "designer") with the following properties:

The Virticle Scroll bar is 24 Width and Form.Height-24 Tall at (Form.Width-24,0)

(24 wide,streching from the top to 24 short of the bottom anchored on the right)

Same for the Horisontal but its on the bottom streching the width - 24 (and 24 tall)

here is my code (its for a map editor for a recreation of Sid Meiers Railroad Tycoon).

public class mapVScroll : VScrollBar
{
protected override void OnResize(EventArgs e)
{
	base.OnResize (e);
	if(Parent == null)
		return;
	Maximum = (((MAPVIEWER)Parent).Height - Height)/((MAPVIEWER)Parent).TileViewSize;
	if(Value > Maximum)
		Value = Maximum;
}
public mapVScroll(){}
}
public class mapHScroll : HScrollBar
{
protected override void OnResize(EventArgs e)
{
	base.OnResize (e);
	if(Parent == null)
		return;
	Maximum = (((MAPVIEWER)Parent).Height - Height)/((MAPVIEWER)Parent).TileViewSize;
	if(Value > Maximum)
		Value = Maximum;
}
public mapHScroll(){}
}

public class MAPVIEWER : Form
{
mapHScroll hscroll;
mapVScroll vscroll;
GTEXMAN TexManager{get{return ((clsMapEditor)MdiParent).texman;}}
public int TileViewSize{get{return 64;}}
public MAP map{get{return((clsMapEditor)MdiParent).map;}}
public MAPVIEWER()
{
	SetStyle(ControlStyles.DoubleBuffer,true);
	SetStyle(ControlStyles.AllPaintingInWmPaint,true);
	MaximizeBox = false;
	hscroll = new mapHScroll();
	vscroll = new mapVScroll();
	
	Controls.Add(hscroll);
	Controls.Add(vscroll);

	hscroll.Location = new System.Drawing.Point(0,Width-24);
	hscroll.Size = new System.Drawing.Size(Height-24, 24);
	hscroll.Anchor = (AnchorStyles)(AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);

	vscroll.Location = new System.Drawing.Point(Height-24, 0);
	vscroll.Size = new System.Drawing.Size(24, Width-24);
	vscroll.Anchor = (AnchorStyles)(AnchorStyles.Top | AnchorStyles.Bottom| AnchorStyles.Right);

	OnResize(new EventArgs());
}
protected override void OnPaint(PaintEventArgs e){base.OnPaint(e);}
protected override void OnClick(EventArgs e){base.OnClick(e);}
protected override void OnResize(EventArgs e)
{
	base.OnResize(e);
	if(Height < TileViewSize*6)
		Height = (TileViewSize*7) + 24;
	if(Width < TileViewSize*6)
		Width = (TileViewSize*7) + 24;
	if((Width-24)%TileViewSize!=0)
		Width -= (Width-24)%TileViewSize;
	if((Height-24)%TileViewSize!=0)
		Height -= (Height-24)%TileViewSize;
}
}

Why will the scroll bars not go where they are supposed too?

(Currently for me the virticle scroll bar appears to be about 12 pixels to the right of where it should be and im yet to find the horisontal one (im guessing its just below the form))

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...