我试图垂直滚动一系列的矩形.每个矩形与下一个矩形具有固定的距离.第一个矩形绝不能低于屏幕顶部10个像素,同样最后一个矩形绝不能超过文本框上方20个像素.换句话说,我正在模仿Windows Phone中的SMS应用程序.
理论上,下面的方法应该动态地滚动矩形,而在某些情况下,一些矩形比它们应该更接近(最终重叠).当屏幕上的轻弹很慢时,效果似乎会放大.
private void Flick()
{
int toMoveBy = (int)flickDeltaY;
//flickDeltaY is assigned in the HandleInput() method as shown below
//flickDeltaY = s.Delta.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;
for (int i = 0; i < messages.Count; i++)
{
ChatMessage message = messages[i];
if (i == 0 && flickDeltaY > 0)
{
if (message.Bounds.Y + flickDeltaY > 10)
{
toMoveBy = 10 - message.Bounds.Top;
break;
}
}
if (i == messages.Count - 1 && flickDeltaY < 0)
{
if (message.Bounds.Bottom + flickDeltaY < …Run Code Online (Sandbox Code Playgroud) 我有一个表格,我正在使用ShowDialog它包含几个文本框,标签和一个按钮.我遇到的问题是文本框是在表单本身之前绘制的,而其他控件是在绘制之前绘制的.
我重写了这个OnPaint方法我不确定这是否会导致问题:
protected override void OnPaint(PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.Black, ButtonBorderStyle.Solid);
base.OnPaint(e);
}
Run Code Online (Sandbox Code Playgroud)
这只是一个轻微的延迟,但它是可见的和恼人的.谢谢.
顺便说一下,表格是双缓冲的.
编辑:我已经确定问题是表格没有FormBorderStyle.随着FormBorderStyle设置Sizable,不会发生此问题.但请注意,FormBorderStyle.None我的边框样式是必要的,所以我还没有找到解决方案.
我正在尝试使用此处给出的构建指令为一个简单的protobuf 示例生成代码。我已经尝试了一段时间,但在源根目录中看不到任何自动生成的代码。
以下是我的build.gradle档案
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.5'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.google.protobuf'
group = 'io.ai.vivid'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.228'
}
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.5.1-1"
}
generateProtoTasks.generatedFilesBaseDir = 'generated-sources'
plugins …Run Code Online (Sandbox Code Playgroud) 是否有一种redo在C#中执行作业的等效方法?即返回循环的顶部并重新执行而不检查条件或增加循环计数器.谢谢.
我有以下XAML,它意味着在它旁边显示一个Image和两个TextBlocks顶部:
<StackPanel Orientation="Horizontal" >
<Image Source="{Binding CoverArt}" Height="150" />
<StackPanel Orientation="Vertical">
<StackPanel>
<TextBlock FontSize="30" Text="{Binding Title}" TextWrapping="Wrap" />
</StackPanel>
<Grid Width="auto">
<TextBlock FontSize="22" Text="{Binding Summary}" TextWrapping="Wrap" />
</Grid>
</StackPanel>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
我的问题是让文本换行.我已经尝试使用a Grid并指定列的宽度,但它不起作用.也没有将宽度值设置为自动.唯一有效的是硬编码宽度,但我不希望这样.谢谢.
我有以下方法来打开和反序列化XML文件:
private static object DeserializeFile(string fileName, Type type)
{
Stream openFile = TitleContainer.OpenStream(fileName);
XmlSerializer reader = new XmlSerializer(type);
return reader.Deserialize(openFile);
}
Run Code Online (Sandbox Code Playgroud)
我用它多次打开包含不同对象的不同文件.目前我必须以下列方式使用它:
City gameCity = (City)DeserializeFile(GameData.CITIES_FILE, typeof(City));
Run Code Online (Sandbox Code Playgroud)
我觉得可以通过使方法返回一个对象作为参数传入的类型来避免类型转换.谢谢.
我有一小部分游戏,它基本上显示了一本书的页面.Update方法没有做任何事情,Draw方法如下:
public override void Draw(GameTime gameTime)
{
SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
spriteBatch.Begin();
spriteBatch.Draw(background.Image, background.Bounds, Color.White);
spriteBatch.DrawString(font, name, new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 2 - font.MeasureString(name).X / 2, 100), Color.Black);
spriteBatch.DrawString(font, currentPage.PageText, new Vector2(currentPage.TextArea.X, currentPage.TextArea.Y), Color.Black);
if (currentPageNumber != 1)
{
spriteBatch.Draw(next.Image, previous.Bounds, null, Color.White, 0.0F, Vector2.Zero, SpriteEffects.FlipHorizontally, 0.0F);
}
if (currentPageNumber != noOfPages)
{
spriteBatch.Draw(next.Image, next.Bounds, Color.White);
}
DrawEmptyRectangle(spriteBatch, 3F, Color.Black, new Rectangle(back.Bounds.X - 1, back.Bounds.Y - 1, back.Bounds.Width + 1, back.Bounds.Height + 1));
DrawEmptyRectangle(spriteBatch, 3F, Color.Black, new Rectangle(play.Bounds.X - 1, play.Bounds.Y …Run Code Online (Sandbox Code Playgroud) 我使用以下代码更新我的类中的标签,该标签扩展UserControl:
private delegate void LabelChanger(bool signedIn);
public bool SignedIn
{
get { return _signedIn; }
set
{
_signedIn = value;
labelChanger(value);
}
}
private void labelChanger(bool signedIn)
{
if (label1.InvokeRequired)
{
BeginInvoke(new LabelChanger(labelChanger), signedIn);
}
label1.Text = signedIn ? "Sign Out" : "Sign In";
}
Run Code Online (Sandbox Code Playgroud)
问题是,当代码设置标签文本时,UI会更新,但是我在面板上得到一个"InvalidOperationException",它是标签的父级.有什么想法吗?谢谢.
c# ×6
winforms ×2
xna ×2
.net ×1
for-loop ×1
gradle ×1
java ×1
loops ×1
memory-leaks ×1
onpaint ×1
reflection ×1
ruby ×1
silverlight ×1
xaml ×1