Fit the GoGrid size to GoView size

Hi!

I need to fit my GoGrid size to GoView size, which contains it.
I did the following:

  1. I derrived my class from GoGrid

  2. I subscribed on GoView events:

    this.View.SizeChanged += GoViewSizeChangedEventHandler;


    this.View.PropertyChanged += GoViewPropertyChangedEventHandler;
  3. Events handlers of these events contains the same code (in PropertyChanged event handler this code will execute if e.PropertyName == “DocScale”):

    this.Bounds = new RectangleF(0, 0,

    View.DocExtent.Width > View.Document.Bounds.Width ? View.DocExtent.Width : View.Document.Bounds.Width,

View.DocExtent.Height > View.Document.Bounds.Height ? View.DocExtent.Height : View.Document.Bounds.Height);

It works almost exactly as i need, but sometimes the size of the GoGrid and the GoView doesn't equal each other. Is there a mistake in my events handlers? Or may be i passed something important? Thanks!

Can you explain more about the requirement driving this? What does it matter if the grid continues out past the edge of the view?

I have tried to do that in DrawDemo example.
I added the creation of the GoGrid for the goView1 into MainForm constructor:

  ...
  var grid = new GoGrid();
  grid.Style = GoViewGridStyle.Line;
  grid.CellSize = new SizeF(25, 25);
  goView1.Grid = grid;      
  goView1.Document = mydoc;      
  goView1.SizeChanged += new EventHandler(goView1_SizeChanged);
  goView1.PropertyChanged += new PropertyChangedEventHandler(goView1_PropertyChanged);
  ComputeGridSize();
  ...

ComputeGridSize method:
... 
private void ComputeGridSize()
{
    if (goView1.Grid != null)
    {            
        goView1.Grid.Bounds = new RectangleF(0, 0,
                    goView1.DocExtent.Width > goView1.Document.Bounds.Width ? goView1.DocExtent.Width : goView1.Document.Bounds.Width,
                    goView1.DocExtent.Height > goView1.Document.Bounds.Height ? goView1.DocExtent.Height : goView1.Document.Bounds.Height);
    }
}
...

Events handlers:
...
void goView1_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
    if (e.PropertyName == "DocScale")
    {
        ComputeGridSize();
    }
}

void goView1_SizeChanged(object sender, EventArgs e)
{
    ComputeGridSize();
}
...

After the example was started, bounds of the goView1.Grid don’t correspond to goView1.Bounds. It takes place and then i change the scale of goView1 and its size. M<span =“hps”>ismatch <span =“hps”>bounds <span =“hps”>can also be observed <span =“hps”>when you <span =“hps”>using <span =“hps”>ClickCreateTool, when <span =“hps”>the <span =“hps”>created object <span =“hps”>is out of <span =“hps”>view (It happens when there are scrolls exist on the view).

It must be i did something wrong…

maybe a screenshot or two would help me understand what you’re trying to do…

OK, I think the thing you are missing is that the GoView doesn’t have to be displaying the 0,0 point of the document. I think you want to place the origin of the grid at GoView.DocPosition… assuming I now understand your goal.