小编Wai*_*ong的帖子

C# 在面板周围拖动控件

我正在开发一个系统,允许用户在同一面板内拖动对象,我进行了一些研究,发现我应该使用鼠标事件,如 mouse_up、mouse_down 和 mouse_move。

该程序将生成 3 个图片框,并允许用户在面板内的每个图片框周围拖动,但我代码的程序不能完美工作,因为当我拖动图片框时,图片框会移动,但不会根据我的鼠标光标移动位置,它在其他地方,此外,拖动时,面板中有图片框阴影,我尝试过那些 update()、refresh() 和 invalidate() 但似乎对我没有用。以下是我的代码,感谢您的帮助

public partial class Form1 : Form
{

    List<PictureBox> pictureBoxList = new List<PictureBox>();
    private bool isDragging = false;

    public Form1()
    {
        InitializeComponent();

        for (int i = 0; i < 3; i++)
        {
            PictureBox picture = new PictureBox
            {
                Name = "pictureBox" + i,
                Size = new Size(20, 20),
                Location = new Point(i * 40, i * 40),
                BorderStyle = BorderStyle.FixedSingle,
                SizeMode = PictureBoxSizeMode.Zoom,
                ImageLocation = "A.jpg"
            };
            pictureBoxList.Add(picture);


            foreach (PictureBox …
Run Code Online (Sandbox Code Playgroud)

c# draggable mouseevent winforms

4
推荐指数
1
解决办法
5853
查看次数

Android RTL布局方向对齐中心问题

我正在开发一个需要支持阿拉伯语的Android应用程序.(应该从右到左阅读).在快速搜索解决方案后,我发现android完全支持阿拉伯语言本身在API级别17中的声明

机器人:supportsRtl = "真"

在AndroidManifest里面的应用程序标签中,这样我就可以使用布局镜像来自动翻转布局,从而获得更好的从右到左的阅读体验.但是,我注意到在布局镜像期间在子RelativeLayout内部的视图中使用centerInParent时会出现问题.以下是我的代码和预期的布局.

<RelativeLayout
    android:background="@color/white"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:padding="20dp">

    <RelativeLayout
        android:background="@drawable/shape_flag_imageview_boarder"
        android:id="@+id/imageLayout"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">

        <ImageView
            android:id="@+id/image"
            android:layout_height="100dp"
            android:layout_width="100dp"
            android:visibility="invisible" />

        <ProgressBar
            android:id="@+id/progressbar"
            android:layout_centerInParent="true"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content" />

    </RelativeLayout>

    <TextView
        android:id="@+id/text"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginTop="10dp"
        android:layout_toEndOf="@id/imageLayout"
        android:layout_width="wrap_content"
        android:text="Some text here bla bla bla"
        android:textColor="@color/black" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

从左到右的正常布局

上图显示了从左到右的正常布局方向的预期结果.我在一个子视图中将ImageView和ProgressBar包装在一起的目的是因为我希望在从Internet加载图像时,在ImageView中间显示ProgressBar.在我将Locale更改为阿拉伯语后,它变得像 在RTL中布局
正如我尝试和错误并弄清楚这是由ProgressBar的centerInParent引起的.它不是以子视图为中心,而是将中心与根外父视图对齐,后者是最外层的RelativeLayout.下面是从ProgressBar中删除centerInParent代码的屏幕截图.

在此输入图像描述

它清楚地显示布局镜像效果很好,但ProgressBar位置不是我所期望的.所以我尝试使用centerVertical和centerHorizo​​ntal,结果分别显示在下面的图像中. 在此输入图像描述 在此输入图像描述

这些解决方案都不起作用,我搜索过的主题都与此问题无关.所以我猜这可能是Android库中的一个错误?如果有人知道问题或解决方案,请与我分享.谢谢

android alignment arabic android-layout right-to-left

4
推荐指数
1
解决办法
2857
查看次数