直到Canvas中没有空格

直到Canvas中没有空格

本文介绍了在每行中绘制矩形,直到Canvas中没有空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好专家



我正在研究WPF windows应用程序,我试图通过vb.net创建Rectangle



我能够只做一行。

我需要在每一行重复此操作,直到画布中没有位置。



这是我的XAML

Hello Experts

I am working on WPF windows application where I am trying to create Rectangle through vb.net

I am able to do it for just one row.
I would need to repeat this on Each row until there is no place in the Canvas.

Here is my XAML

<Grid>
            <ScrollViewer CanContentScroll="True" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="visible">
                <Canvas Height="700" Width="1200" Name="front_canvas" Grid.Row="3" Grid.Column="2" >
                    <Canvas.RenderTransform>
                        <ScaleTransform ScaleX="1" ScaleY="1" />

                    </Canvas.RenderTransform>

</Canvas>
</scrollviewer>
</Grid>





这是我的Vb.net



Here is my Vb.net

Private _top As Double = 0
Protected Sub DrawRect()

            'init rectangles
            'front_canvas.Width - 1 Step 1100
                               For i As Integer = 1 To front_canvas.Width - 1 Step 100
                        Dim rect As New Rectangle()
                        rect.StrokeThickness = 1
                        rect.Stroke = System.Windows.Media.Brushes.Black
                        rect.Width = 50
                        rect.Height = 50
                        rect.Name = "box" + i.ToString()
                        If Not i / 2 = 0 Then
                            Canvas.SetLeft(rect, i)
                     Canvas.SetTop(rect, Top)
                    _top += rect.Height
                        End If

                        _rectangles.Add(rect)
                    Next
                    For Each rect In _rectangles
                        front_canvas.Children.Add(rect)
                    Next
              End Sub 





我正在寻找类似下面的东西



I am looking for something like below

o o o o
o o o o
o o o o

or

oo oo oo oo
oo oo oo oo
oo oo oo oo











上面的所有o都是我的情况下的矩形。



使用当前代码我的应用程序显示如下








All the o's in the above are Rectangles in my case.

With the current code my application shows like below

o o o o o o o o 







感谢一些帮助




Would appreciate some help in this

推荐答案


这篇关于在每行中绘制矩形,直到Canvas中没有空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 14:36