So I have 2 controls on my main form, a custom hexbox control and a richtextbox as in the picture below (It wouldnt let me post an image so will have to follow the link). What I would like to do is depending on where the user has clicked in the hexbox control, the rich textbox on the right will scroll to an associated line.
https://i.stack.imgur.com/8PfRt.jpg
The current issue I’m having is that the code to handle the hexbox click is contained in a separate class (hexbox.cs) and so I’m not able to then take the location of the click and scroll to the associated line in the richtextbox which is contained in the mainform class. I attempted to create a new instance of the mainform to access the richtextbox but obviously this results is the creation of a new richtexbox with none of the original content.
Heres the code in the hexbox class that deals with a mouse click if its any help:
void SetCaretPosition(Point p)
{
System.Diagnostics.Debug.WriteLine("SetCaretPosition()", "HexBox");
if (_byteProvider == null || _keyInterpreter == null)
return;
long pos = _bytePos;
int cp = _byteCharacterPos;
if(_recHex.Contains(p))
{
BytePositionInfo bpi = GetHexBytePositionInfo(p);
pos = bpi.Index;
cp = bpi.CharacterPosition;
SetPosition(pos, cp);
ActivateKeyInterpreter();
UpdateCaret();
Invalidate();
}
else if(_recStringView.Contains(p))
{
BytePositionInfo bpi = GetStringBytePositionInfo(p);
pos = bpi.Index;
cp = bpi.CharacterPosition;
SetPosition(pos, cp);
ActivateStringKeyInterpreter();
UpdateCaret();
Invalidate();
}
}
If I undersntand properly, this should help.
If you have access to hexbox class, you can expose event (MouseClick – or similar) – or even create your own with args prividig selected line – subscribe to this event in your Form.
Then when user click your form class’ll be notified .