我需要知道一个(移动)形式是否悬停在一个组件上(可能是没有鼠标的MouseEnter和MouseLeave).
我有这个想法,即获取组件的左,上,高,宽,并计算(移动)表单的位置是否在表单的位置内.(我不确定如何做到这一点)
有关实施我的想法的任何建议?有没有其他方法可以做到这一点?
将组件准确放置在JFrame上所需位置的可靠推荐方法?
在我的例子中,我有一个简单的Jframe充当菜单.框架由顶部的标签和中间的三个按钮组成.使用自由设计,3个按钮似乎漂浮在框架上,当我运行项目时,它们会转变为难看的位置.只有当3个按钮被拖动到最大长度(到框架的每一侧)时,它们才会表现为"锁定到位".这非常难看.我希望3个按钮位于框架中间的中心位置.
我正在使用Netbeans.自由设计是我一直在使用的,但只有当有很多组件才能将它们"插入"到其他位置时才有用.使用其他设置布局管理器无效.具有经验的人如何处理这样的问题?
我对彻底的学习很感兴趣.如果这个问题很痛苦,业余人士至少可以推荐一本教科书或其他GUI学习资源吗?(我已经两次使用"首先使用java的对象",他们只对GUI构建有非常基本的解释).
谢谢你的任何指示.
我想知道是否可以在运行时知道组件的类别.例如,如果我有一个TLabel,则类别为标准,这意味着组件TLabel位于标准工具选项板中.
我需要检查组件是否是我自己的创作之一,因为我有很多新组件,我不想检查很多ifs条件......
谢谢
在这段代码中:
unit MSEC;
interface
uses
Winapi.Windows, Vcl.Dialogs, Vcl.ExtCtrls, System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls;
type
TMSEC = class(TWinControl)
private
FOpr :TComboBox;
public
constructor Create(AOwner: TComponent); override;
end;
implementation
const
DEF_OPERATIONS :array[0..3] of Char = ('+', '-', '*', '/');
constructor TMSEC.Create(AOwner: TComponent);
var i :Integer;
begin
inherited;
FOpr:= TComboBox.Create(Self);
with FOpr do begin
Parent:= Self;
Align:= alLeft;
Width:= DEF_OPERATIONS_WIDTH;
Style:= csDropDownList;
//error in next lines :
Items.Clear;
for i := Low(DEF_OPERATIONS) to High(DEF_OPERATIONS) do Items.Add(DEF_OPERATIONS[i]);
ItemIndex:= 0;
end;
end;
end.
Run Code Online (Sandbox Code Playgroud)
当我更改ComboBox项目时,程序会中断消息:
'Control'没有父项.
如何修复此错误或以其他方式初始化ComboBox项?
我正在做一个自定义组件,Delphi XE2中TComponent的后代,我想右键单击它并有2个选项:Next和Previous(例如)
怎么办?请提供代码段或示例.
该选项应该在设计时出现,右键单击表单上的组件,现在是TComponent的后代.但如果有更好的选择来获得功能,则不需要这样做.
下一个和上一个将用于根据集合中的主题切换组件的颜色(通过所有者组件列表).
我希望我的组件在一个单一的属性中具有颜色属性Colors
.而且我已经这样做了,但我得到了"访问冲突".我不明白为什么,因为这是StackOverflow上发布的许多示例中的代码...
unit SuperList;
interface
uses Windows, Controls, Graphics, Classes, SysUtils, StdCtrls;
type
TListColors = class(TPersistent)
private
FNormalBackg:TColor;
FNormalText:TColor;
FNormalMark:TColor;
public
constructor Create;
procedure Assign(Source: TPersistent); override;
published
property NormalBackg:TColor read FNormalBackg write FNormalBackg default clRed;
property NormalText:TColor read FNormalText write FNormalText default clRed;
property NormalMark:TColor read FNormalMark write FNormalMark default clRed;
end;
TSuperList = class(TCustomControl)
private
FColors: TListColors;
procedure SetListColors(const Value:TListColors);
public
procedure Paint; override;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Colors:TListColors read FColors write …
Run Code Online (Sandbox Code Playgroud) 谁能告诉我在我的主页组件上单击提交后如何清除所有输入?我尝试在 subjectForm 组件中的 preventdefault 之后使用 reset() 但是我用错了它或者它不起作用。我还尝试使用 setState 并将我的输入恢复为空的默认状态,但它也不起作用。
我的代码中的所有内容都可以正常工作,但是每次我提交主题时,该字段都不会自行清除
这是我的主页组件。
import React from 'react';
import SubjectForm from './SubjectForm';
import {addSubject} from '../actions/subjectAction';
import {connect} from 'react-redux';
const HomePage=({dispatch})=>(
<div>
<SubjectForm onSubmit ={(subject)=>
dispatch(addSubject(subject))
}/>
</div>
)
export default connect()(HomePage);
Run Code Online (Sandbox Code Playgroud)
这是我的 subjectForm 组件
import React from 'react';
export default class SubjectForm extends React.Component{
constructor(props){
super(props);
this.state={...}
onNameChange =(e)=>{...}
onHourChange =(e)=>{...}
onSubmit=(e)=>{
e.preventDefault();
**//I tried using reset() here but it did not work**
if(!this.state.subjectName){...}
render(){
return (
<div>
{this.state.error && <p>{this.state.error}</p>} …
Run Code Online (Sandbox Code Playgroud) 我在 vueJs @error 处理程序中遇到了一个奇怪的问题,我想要
做的是隐藏带有损坏链接的图像,并显示一个占位符,但是如果我有两个图像并且它们都有一个损坏的链接,只有断开链接的第一张图像显示占位符,而另一个带有断开链接的图像仅显示,浏览器的断开图像默认徽标
这是我为测试所做的代码,我知道这不是在 Vue 中编写代码的正确方法,但它是用于测试目的
<div id="app">
<img width="25%" id="img" src="https://upload.wikimedia.org/wikipedia/commons/5/54/Wallpaper-img_0254.jpg" @error="handle()">
<img width="25%" id="img" src="https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg?auto=compress&cs=tinysrgb&h=350" @error="handle()">
<img v-show="ifImageBroken" src="https://via.placeholder.com/300">
<p>{{brokenText}}</p>
<HelloWorld/>
</div>
<script>
import HelloWorld from "./components/HelloWorld";
export default {
name: "App",
data () {
return {
ifImageBroken: false,
brokenText: ''
}
},
components: {
HelloWorld
},
methods: {
handle : function() {
document.getElementById('img').style.display = 'none'
this.ifImageBroken = true;
this.brokenText = 'unable to load image'
}
}
};
</script>
Run Code Online (Sandbox Code Playgroud)
我只是想知道,这个@error
指令是否可以处理多种损坏图像的情况
是否有任何最佳实践可以在 React 组件中强制使用属性?
还有无论如何将属性设置为不可为空,所以它不会是null
或undefined
?
我有这个功能组件,它在将数据推送到数组时不会更新:
const Experience = (props) => {
let experience = [{
from:"",
to:"",
employer_name:"",
employer_number:""
}];
function addExperience() {
experience = [...experience, {
from:"",
to:"",
employer_name:"",
employer_number:"",
}];
}
return (
<>
{experience.map((val, idx) => {
let id = `exp-id-${idx}`
return(
<div key={idx} id={id}>
...
</div>
)
})}
<button onClick={addExperience}>Add experience</button>
</>
)
}
Run Code Online (Sandbox Code Playgroud)
单击添加体验时,映射未更新,有什么帮助吗?
components ×10
delphi ×5
reactjs ×3
javascript ×2
categories ×1
combobox ×1
delphi-xe2 ×1
forms ×1
java ×1
onerror ×1
properties ×1
reset ×1
swing ×1
vue.js ×1