- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 AnimateWindow
API 来显示或隐藏带有幻灯片动画的 Form
。问题是,如果表单包含一个 RichTextBox
控件,它就不会正确显示该控件。它是透明的,不显示任何文本。
动画完成后,双击控件中的某处将显示文本行。
我已经创建了一个完整的示例,任何人都可以使用它来编译和测试自己。没有更好的调试方法,除非您已经知道答案。
主窗体中有 2 个按钮,一个用于显示另一个窗体,另一个用于隐藏同一个窗体。我将 RichTextBox
添加为简单的 TextBox
。正如您将看到的,问题只发生在 RichTextBox
上。
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsFormsApplication1 {
static class Program {
public const int AW_ACTIVATE = 0x00020000;
public const int AW_HIDE = 0x00010000;
public const int AW_HOR_NEGATIVE = 0x00000002;
public const int AW_HOR_POSITIVE = 0x00000001;
public const int AW_SLIDE = 0x00040000;
[DllImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AnimateWindow(IntPtr hWnd, int time, int awFlags);
[STAThread]
public static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public class Form1 : Form {
public Form form;
public Form1() {
InitializeComponent();
form = new Form2();
form.Show();
form.Hide();
}
private void button1_Click(object sender, EventArgs e) {
form.Location = new Point(Location.X, Location.Y + form.Height + 100);
Program.AnimateWindow(form.Handle, 1000, Program.AW_SLIDE | Program.AW_HOR_NEGATIVE | Program.AW_ACTIVATE);
form.Show();
}
private void button2_Click(object sender, EventArgs e) {
Program.AnimateWindow(form.Handle, 1000, Program.AW_HIDE | Program.AW_HOR_POSITIVE);
form.Hide();
}
#region Windows Form Designer generated code
private void InitializeComponent() {
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button1.Location = new System.Drawing.Point(11, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(133, 114);
this.button1.TabIndex = 0;
this.button1.Text = "SHOW";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button2.Location = new System.Drawing.Point(150, 12);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(133, 114);
this.button2.TabIndex = 1;
this.button2.Text = "HIDE";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(294, 138);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
}
public class Form2 : Form {
public Form2() {
InitializeComponent();
}
#region Windows Form Designer generated code
private void InitializeComponent() {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form2));
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.richTextBox1.Location = new System.Drawing.Point(0, 0);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(240, 50);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";
this.textBox1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.textBox1.Location = new System.Drawing.Point(0, 57);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox1.Size = new System.Drawing.Size(240, 50);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(240, 107);
this.ControlBox = false;
this.Controls.Add(this.textBox1);
this.Controls.Add(this.richTextBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "Form2";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Form2";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.TextBox textBox1;
}
}
注意:我正在为此悬赏,所以如果你要回答,请回答一个有效的解决方案,而不是让我尝试的东西,看看它是否有效。为什么?因为如果人们赞成您的答案并且没有解决任何问题,它仍将被标记为已接受但没有帮助。感谢您的理解。
最佳答案
请看这段代码...这是我见过的最奇怪的错误...唯一的区别是我必须捕获 RichTextBox 的 VisibleChanged 事件,并设置 Capture
属性,更新它,然后关闭 Capture
,我认为是向控件发送消息以强制双击事件,但发现这不是必需的......我也有覆盖 form2
本身的 OnActivated 事件,以便在动画完成后 捕获事件并强制刷新...奇怪的奇怪错误....
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Text;
namespace WindowsFormsApplication1
{
static class Program
{
public const int AW_ACTIVATE = 0x00020000;
public const int AW_HIDE = 0x00010000;
public const int AW_HOR_NEGATIVE = 0x00000002;
public const int AW_HOR_POSITIVE = 0x00000001;
public const int AW_SLIDE = 0x00040000;
[DllImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AnimateWindow(IntPtr hWnd, int time, int awFlags);
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public class Form1 : Form
{
public Form form;
public Form1()
{
InitializeComponent();
form = new Form2();
form.Show();
form.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
form.Location = new Point(Location.X, Location.Y + form.Height + 100);
Program.AnimateWindow(form.Handle, 1000, Program.AW_SLIDE | Program.AW_HOR_NEGATIVE | Program.AW_ACTIVATE);
form.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Program.AnimateWindow(form.Handle, 1000, Program.AW_HIDE | Program.AW_HOR_POSITIVE);
form.Hide();
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button1.Location = new System.Drawing.Point(11, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(133, 114);
this.button1.TabIndex = 0;
this.button1.Text = "SHOW";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button2.Location = new System.Drawing.Point(150, 12);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(133, 114);
this.button2.TabIndex = 1;
this.button2.Text = "HIDE";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(294, 138);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
}
public class Form2 : Form
{
public Form2()
{
InitializeComponent();
this.richTextBox1.VisibleChanged += new EventHandler(richTextBox1_VisibleChanged);
}
void richTextBox1_VisibleChanged(object sender, EventArgs e)
{
if (this.richTextBox1.Visible)
{
System.Diagnostics.Debug.WriteLine("Visible!");
this.richTextBox1.Capture = true;
this.richTextBox1.Update();
this.richTextBox1.Capture = false;
this.richTextBox1.Refresh();
}
else System.Diagnostics.Debug.WriteLine("InVisible!");
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form2));
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.richTextBox1.Location = new System.Drawing.Point(0, 0);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(240, 50);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";
this.textBox1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.textBox1.Location = new System.Drawing.Point(0, 57);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox1.Size = new System.Drawing.Size(240, 50);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(240, 107);
this.ControlBox = false;
this.Controls.Add(this.textBox1);
this.Controls.Add(this.richTextBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "Form2";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Form2";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
System.Diagnostics.Debug.WriteLine("OnActivated");
this.Refresh();
}
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.TextBox textBox1;
}
}
代码仍然有效 - 一件非常晦涩的事情 - 有趣的是在 VisibleChanged
处理程序中,我期望在单击“隐藏”按钮时调试输出显示“InVisible”,但它没有。我确实尝试使用 WM_PRINT
和 WM_PRINTCLIENT
消息,但富文本框失败了,只是不要问我为什么要在富文本框本身上设置捕获并强制刷新解决了它......这是来自MSDN的引述对此:
The window procedures for the window and its child windows should handle any WM_PRINT or WM_PRINTCLIENT messages. Dialog boxes, controls, and common controls already handle WM_PRINTCLIENT. The default window procedure already handles WM_PRINT. If a child window is displayed partially clipped, when it is animated it will have holes where it is clipped.
我不知道是否值得麻烦向 Microsoft 指出这一点并说“AnimateWindow 或 RichTextBox Control with .NET 中存在错误”,无论哪种方式,都很难确定,因为在动画完成,文本框显示正常,但富文本框不正常,但在捕获打开时显式使用 Capture
和 Update
,强制执行刷新...它在错误本身上双向摆动 - 可能在两个位置...无论如何非常不寻常和奇怪..希望代码对您有用。
关于c# - RichTextBox 的 AnimateWindow API 透明度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3507355/
我正在制作一个应用程序,我需要使用 ffmpeg 将两个视频文件叠加在另一个之上。 .我尝试了各种命令,但它所做的只是合并视频。 最佳答案 基本方法是 ffmpeg -i in1 -i in2 -fi
我将 Qt3D 与 offscreen renderer 结合使用并修改框架图以包含背景图像,例如 here . 不幸的是,使用 QPhongAlphaMaterial 为绘制在背景图像上的对象添加透
我正在开发的这个组件有视觉问题。它是带有 2 个 JTextField 和 2 个 JLabel 的 JPanel。我不能做坚实的背景。我尝试了几种不透明/背景颜色组合但没有成功。 我不允许附加图像,
我正在使用 Gnuplot 成功绘制一些时间序列数据。然而,该系列相当密集(大约 5 英寸空间中有 10,000 个样本),当我绘制多个系列时,很难看到绘制在顶部的系列下方。 有什么方法可以使线条具有
我正在尝试设置一个自定义拖动图标以在 NSTableView 中使用。一切似乎都正常,但由于我对 Quartz 缺乏经验,我遇到了问题。 - (NSImage *)dragImageForRowsWi
是否可以制作例如 20% 透明的 TMemo 或其他 vcl 组件?像 TButton 或 TEdit 吗? 在谷歌搜索解决方案时,我发现了这个: From Here ,然后我想,如果我在窗体上绘制图
我目前正在学习如何使用 Scenekit,并且遇到了透明对象的问题。我写了一个着色器来增加正面看脸时的透明度,当我选择白色背景时,一切都按预期工作...... transparency with wh
我对 openGL 中的 alpha 混合有疑问... 我尝试了一些绘制透明对象的方法...通过在绘制透明面之前禁用 GL_DEPTH_TEST 并在绘制透明面后再次重新启用 GL_DEPTH_TES
我正试图让我的背景 webView 像那样透明: webView.setBackgroundColor(0x00000000); 但它不起作用,如果我添加这一行,一切都是透明的(我看不到我的 html
我目前正在创建一个应用程序并且出现了这个问题,我想让 TabLayout 透明。当我使用 RelativeLayout TabLayout 覆盖内容时,当我使用 LinearLayout TabLay
我有一个 UINavigationItem(不是 UINavigationBar),我想使其透明或不透明。这是在我建立从导航 Controller 到我的 UIViewController 子类的关系
是否可以让您的 android Activity 以透明模式在当前正在运行的 Activity 之上运行,以便您可以通过它看到它下面的 Activity ?如果可能,您可以设置不同级别的透明度吗? 最
我正在使用 noUiSlider 范围 slider 。这是 jsfiddle: https://jsfiddle.net/oun5p1xz/ behaviourSlider = document.g
有没有办法改变控制台的不透明度使其半透明? 还有办法将控制台的背景颜色更改为自定义颜色吗? 最佳答案 快速谷歌显示 this site其中包含用于具有透明窗口的控制台应用程序的代码。 本质上,您必须获
主.xml: 这是我的 main.xml,我试图使按钮最透明,但我仍然想看到它们,但我不知道要添加什么以及在哪里添加,请用低不透明度更正我的 xml在按钮
如何将实际内容 Pane 的背景设置为不透明,我添加到其中的面板我已经设置为不透明,但即使我这样做,选项卡 Pane 的主要区域仍显示为蓝色 JTabbedPane tabbedPane = new
是否可以继承颜色但覆盖不透明度值?以下是伪 CSS 中的示例: .color-class { background-color: rgba(255, 0, 0, 0); } .lighten
我正在尝试让我的导航栏变得 100% 透明,以便 UINavigationButtonItems 只可见并且背景(通常为白色)应该显示背景图像。 我试过了 HomeNavigationControll
RGBA 非常有趣,-webkit-gradient、-moz-gradient 和呃... progid:DXImageTransform.Microsoft.gradient 也是如此...是的。
我一直在尝试使用 AppBarLayout,但找不到使它的背景透明的方法。 我的意思是: 这是我的 XML: 如您所见,我使用的是颜色 #8000
我是一名优秀的程序员,十分优秀!