I have some code, it will be create form with button, but when form show button has wrong position.
var
Form: TForm;
Button: TButton;
begin
Form := TForm.Create(Self);
try
Button := TButton.Create(Form);
Button.Parent := Form;
Button.Left := 8;
Button.Top := 8;
Button.Height := 185;
Button.Width := 292;
Button.Anchors := [];
Form.ShowModal;
finally
FreeAndNil(Form);
end;
Any idea how to solve this?
Don't clear the Anchors. That causes the button to move around when the Form is resized. Leave the default Anchors set to [akLeft,akTop] so the button will honor your Left/Top values.
When I use HandleNeeded before create controls
Form.HandleNeeded
When form show - button has correct position
Related
To programmatically select a tab of a Codename One Tabs object, the following code is enough:
tabs.setSelectedIndex(tabToSelect, true);
The problem is that this code selects the wanted tab but it doesn't horizontally scroll the tabs buttons container to make the tab name visible (if it's not visible because there are many tabs). Note that I'm using the theme constant tabsGridBool: false;.
Because of this issue, I tried to solve so:
tabs.setSelectedIndex(tabToSelect, true);
tabs.scrollComponentToVisible(tabs.getTabsContainer().getComponentAt(tabToSelect));
but it doesn't work. What is a proper way to select a tab and its button? Thank you
I tried this and it worked for me, it might be the order of the operations:
Form hi = new Form("Tabs", new BorderLayout());
Tabs t = new Tabs();
hi.add(CENTER, t);
for(int iter = 1 ; iter < 20 ; iter++) {
t.addTab("Tab " + iter, FontImage.MATERIAL_ACCESS_ALARM, 4, new Label("Tab " + iter));
}
Button test = new Button("Test");
test.addActionListener(e -> {
t.getTabsContainer().getComponentAt(18).requestFocus();
t.setSelectedIndex(18, true);
});
hi.add(SOUTH, test);
hi.show();
Need to check if multiple Combo boxes are not empty.
Tried for one combo box, how to apply the same to multiple.
if (combobox1.ItemIndex <> -1) then
begin
btnOK.Enabled := true;
end
else
btnOK.Enabled := false;
PS: I'm new to delphi please bear with mistakes, if any.
The easiest would be a construct like this
if (ComboBox1.ItemIndex = -1) or (ComboBox2.ItemIndex = -1) or (ComboBox3.ItemIndex = -1) then
Exit;
Button1.Enabled := true;
This exits the procedure if any of the comboboxes has -1 selected. If all boxes are selected, the button gets enabled.
Or you could just bind them all together and write directly to the Enabled property
Button1.Enabled := (ComboBox1.ItemIndex <> -1) and (ComboBox2.ItemIndex <> -1) and (ComboBox3.ItemIndex <> -1);
The most beautiful way, if you really have a lot of comboboxes is using arrays
procedure TForm1.SetButtonActive;
var
boxes: array of TComboBox;
box: TComboBox;
begin
boxes := [ComboBox1, ComboBox2, ComboBox3];
for box in boxes do
if box.ItemIndex = -1 then
Exit;
Button1.Enabled := true;
end;
How to draw a border to highlight a SCNNode and indicate to user that the node is selected?
In my project user can place multiple virtual objects and user can select any object anytime. Upon selection i should show the user highlighted 3D object. Is there a way to directly achieve this or draw a border over SCNNode?
You need to add a tap gesture recognizer to the sceneView.
// add a tap gesture recognizer
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
scnView.addGestureRecognizer(tapGesture)
Then, handle the tap and highlight the node:
#objc
func handleTap(_ gestureRecognize: UIGestureRecognizer) {
// retrieve the SCNView
let scnView = self.view as! SCNView
// check what nodes are tapped
let p = gestureRecognize.location(in: scnView)
let hitResults = scnView.hitTest(p, options: [:])
// check that we clicked on at least one object
if hitResults.count > 0 {
// retrieved the first clicked object
let result = hitResults[0]
// get its material
let material = result.node.geometry!.firstMaterial!
// highlight it
SCNTransaction.begin()
SCNTransaction.animationDuration = 0.5
// on completion - unhighlight
SCNTransaction.completionBlock = {
SCNTransaction.begin()
SCNTransaction.animationDuration = 0.5
material.emission.contents = UIColor.black
SCNTransaction.commit()
}
material.emission.contents = UIColor.red
SCNTransaction.commit()
}
}
The snippet above highlights the whole node. You'd have to adjust it to highlight the borders only, if that's what you're looking for.
Disclaimer:
This code was taken directly from Xcode's template code created when opening a new game (SceneKit) project.
I have a Rad Command Bar created with the code below:
RadCommandBar main = new RadCommandBar();
main.Dock = DockStyle.Top;
main.AutoSize = true;
main.Size = new System.Drawing.Size(874, 59);
CommandBarRowElement address = new CommandBarRowElement();
CommandBarStripElement strip = new CommandBarStripElement();
strip.FloatingForm = null;
strip.StretchHorizontally = true;
address.Strips.Add(strip);
CommandBarDropDownList addressEdit = new CommandBarDropDownList();
addressEdit.MaxSize = new System.Drawing.Size(0, 0);
addressEdit.VisibleInOverflowMenu = true;
addressEdit.StretchHorizontally = true;
main.Rows.Add(address);
parent.Controls.Add(main);
I'm having issue with hiding the "Add or Remove Buttons" of the strip element. Can someone point me to the right way to hide that menu?
You can use the following code:
strip.OverflowButton.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
It it better to set the Visibility to Collapsed, in order to collapse the whole item. Using Hidden will hide the item, but its space will be retained. More information is available here: Customize the overflow button
I have OnMouseMove event, during which I want to find a value of certain cell (not neccesarily the one under the mouse). Basically the question is:
How to access cell data using its x and y coordinates without selecting it, changing focus etc?
Tofig, you can use the MouseCoord procedure to get the current row and col, but to show the value of the pos [Col,Row] you must set the DataLink.ActiveRecord property to the Row value and create a new class descendent to access the protected property.
check this code
type
THackGrid = class(TCustomDBGrid); //Create a new class to access the protected properties
procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
Cell : TGridCoord;
Row,Col : integer;
OrigActiveRecord : integer;
begin
inherited;
Cell:=DBGrid1.MouseCoord(X,Y);
Col:= Cell.X;
Row:= Cell.Y;
if dgTitles in DBGrid1.Options then Dec(Row); //if the titles are shown then adjust Row index (-1);
if dgIndicator in DBGrid1.Options then Dec(Col); //if the indicator is shown then adjust the Column index (-1);
if THackGrid(DBGrid1).DataLink.Active and (Row>=0) and (Col>=0) then
begin
OrigActiveRecord:=THackGrid(DBGrid1).DataLink.ActiveRecord; //save the original index
try
THackGrid(DBGrid1).DataLink.ActiveRecord:= Row;
Label1.Caption:=DBGrid1.Columns[Col].Field.AsString; //show the current value in a tlabel
finally
THackGrid(DBGrid1).DataLink.ActiveRecord:= OrigActiveRecord; //restore the index
end;
end;
end;